You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Report details of excess arguments in object_new & object_init #75708
object_new and object_init currently use their own argument checking logic, and hence haven't benefited from the error reporting enhancements in PyArg_ParseTupleAndKeywords
Compare:
>>> str(1, 2, 3, 4, 5, x=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: str() takes at most 3 arguments (6 given)
>>> str(x=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'x' is an invalid keyword argument for this function
To:
>>> C(1, 2, 3, 4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object() takes no parameters
>>> C(x=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object() takes no parameters
bpo-31506 amends the latter to at least report the subclass name rather than the base class name, but doesn't cover any other enhancements, like reporting how many arguments were actually given, or the first unknown keyword argument name.
str(x=1) is not the best example since str() takes keyword arguments. Look at tuple() and list():
>>> tuple(x=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: tuple() takes no keyword arguments
>>> list(x=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list() takes no keyword arguments
Initial version of my patch for bpo-31506 reported error messages similar to tuple() and list(), but at end I simplified it since in any case the error message was not perfect.
Activity
ncoghlan commentedon Sep 20, 2017
object_new and object_init currently use their own argument checking logic, and hence haven't benefited from the error reporting enhancements in PyArg_ParseTupleAndKeywords
Compare:
To:
bpo-31506 amends the latter to at least report the subclass name rather than the base class name, but doesn't cover any other enhancements, like reporting how many arguments were actually given, or the first unknown keyword argument name.
ncoghlan commentedon Sep 20, 2017
Adding a dependency on bpo-31506, as this shouldn't be tackled until those simpler amendments are resolved.
serhiy-storchaka commentedon Sep 20, 2017
str(x=1) is not the best example since str() takes keyword arguments. Look at tuple() and list():
Initial version of my patch for bpo-31506 reported error messages similar to tuple() and list(), but at end I simplified it since in any case the error message was not perfect.