[issue9943] TypeError message became less helpful in Python 2.7
Nick Coghlan
report at bugs.python.org
Sun Sep 26 14:28:50 CEST 2010
Nick Coghlan <ncoghlan at gmail.com> added the comment:
Having seen the reversion go by on the checkins list, I think there are distinctions the interpreter should be making here in order to improve the error messages, but it isn't.
Ideally, we want to be able to tell the user (without writing War and Peace as an error message):
1. How many positional parameters are expected
2. How many positional parameters were supplied as positional arguments
3. How many positional parameters were supplied as keyword arguments
For example:
Def: f(**kw)
Call: f("hello", keyword=True)
Error: f() does not accept positional arguments (1 given)
Def: f(x, **kw)
Call: f("hello", "goodbye", keyword=True)
Error: f() accepts at most 1 positional argument (2 given)
Def: f(x, **kw)
Call: f("hello", x="goodbye", keyword=True)
Error: f() accepts at most 1 positional argument (2 given, 1 via keyword)
Basically:
1. Get rid of the "exactly"/"at most" distinction ("exactly" is wrong, since you can always provide positional arguments as keyword arguments instead)
2. Use "positional" instead of the awkward "non-keyword"
3. Append additional info when some or all of the positional arguments are provided as keywords.
----------
nosy: +ncoghlan
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9943>
_______________________________________
More information about the Python-bugs-list
mailing list