New submission from Nick Coghlan:

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

Issue 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.

----------
messages: 302591
nosy: ncoghlan
priority: normal
severity: normal
stage: needs patch
status: open
title: Report details of excess arguments in object_new & object_init
type: enhancement

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31527>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to