This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TypeError message incorrect for max() with one keyword arg
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: 16543 Superseder:
Assigned To: Nosy List: chris.jerdonek, ezio.melotti, mark.dickinson
Priority: normal Keywords: patch

Created on 2012-11-20 22:36 by chris.jerdonek, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
issue16515.diff ezio.melotti, 2012-11-21 16:06 Patch against 3.2.
issue16515-unpacktuple.diff ezio.melotti, 2012-11-21 18:02 Patch against 3.2 to fix the message in PyArg_UnpackTuple.
Messages (7)
msg176034 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-11-20 22:36
The below should probably say something along the lines of "max expected 1 positional arguments" (since the foo value is an argument):

>>> max(foo=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: max expected 1 arguments, got 0

I imagine this affects other functions, but I haven't looked into which ones.

Here is an example of another built-in function that provides a better message:

>>> sorted(foo=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Required argument 'iterable' (pos 1) not found
msg176044 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-21 08:18
It would be nice to change 'arguments' to 'argument' in this case, too. :-)
msg176063 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-21 16:06
Attached an initial patch:
>>> max()
TypeError: max() requires at least a positional argument
>>> max(foo=3)
TypeError: max() requires at least a positional argument
>>> max(3, foo=3)
TypeError: max() got an unexpected keyword argument
>>> max(3, 4)
4
msg176067 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-21 17:51
Would it make sense to adjust the error messages in PyArg_UnpackTuple instead?  I suspect there are quite a lot of functions using it.
msg176068 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-21 18:02
PyArg_UnpackTuple could be fixed to say "positional argument" (see attached patch (maybe this should be a separate issue)).
The error returned by max() is wrong because PyArg_UnpackTuple is used on the *args alone first, and it has no knowledge of the kwargs.
If PyArg_UnpackTuple is used to parse the *args then adding "positional" should solve the problem, however for this specific case the error would still be incorrect, because max also accepts more positional args.
msg176070 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-21 18:12
Yes, true:  max is probably still going to have to be a special case, thanks to its schizophrenic signature.  (max([1, 2, 3]) versus max(1, 2, 3)).
msg176204 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-23 18:07
I created #16543 for PyArg_UnpackTuple.
Once that is fixed we can continue with this.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60719
2020-10-22 18:35:07iritkatrielsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 2.7, Python 3.2, Python 3.3, Python 3.4
2012-11-23 18:07:53ezio.melottisetdependencies: + improve TypeError messages for missing arguments (meta issue)
messages: + msg176204
2012-11-21 18:12:21mark.dickinsonsetmessages: + msg176070
2012-11-21 18:02:33ezio.melottisetfiles: + issue16515-unpacktuple.diff

messages: + msg176068
2012-11-21 17:51:24mark.dickinsonsetmessages: + msg176067
2012-11-21 16:06:23ezio.melottisetfiles: + issue16515.diff
keywords: + patch
messages: + msg176063

stage: needs patch -> patch review
2012-11-21 15:39:32ezio.melottisetnosy: + ezio.melotti

stage: needs patch
2012-11-21 08:18:06mark.dickinsonsetnosy: + mark.dickinson
messages: + msg176044
2012-11-20 23:24:40chris.jerdoneksettitle: TypeError message incorrect for max() with no args -> TypeError message incorrect for max() with one keyword arg
2012-11-20 22:36:57chris.jerdonekcreate