GeezerVison is showing github.com — gh-87613: Name the subclass in Argument Clinic `__new__` argument errors by cmaloney · Pull Request #160799 · python/cpython
Conversation
cmaloney
commented
Oct 28, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
The tp_new slot is inherited. Because the base type name was embedded in the errors this meant argument errors showed as the base type rather than the subclass. Change them to be the subclass name.
While tp_name would be slightly faster to use it includes the module name like _thread.RLock() which adds confusion. Use _PyType_Name(type) which returns RLock(). Include a test to check.
_PyArg_NoPositional() only short-circuits when args is NULL, which tp_new never gets; use _PyArg_NoPositionalStack() to keep the name lookup off the success path.
The vectorcall cases keep using constant strings since that slot does not inherit.
This is needed to keep parity moving frozenset to Argument Clinic I think in general it makes these error messages a little better for new.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…nt errors
tp_new is inherited, so argument errors from a subclass named the base
type. While `tp_name` would be slightly faster to use it includes the
module name like `_thread.RLock()` which adds confusion. Use
`_PyType_Name(type)` which returns `RLock()`. Include a test to check.
_PyArg_NoPositional() only short-circuits when args is NULL, which
tp_new never gets; use _PyArg_NoPositionalStack() to keep the name
lookup off the success path.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Changed my mind on this, pure python is the other way and I'd argue AC should match that:
>>> class Base:
... def __new__(cls, a): ...
... class Sub(Base): pass
...
... Sub(1, 2) # Base.__new__() takes 2 positional arguments but 3 were given
... Sub(x=1) # Base.__new__() got an unexpected keyword argument 'x'
...
Traceback (most recent call last):
File "<python-input-0>", line 5, in <module>
Sub(1, 2) # Base.__new__() takes 2 positional arguments but 3 were given
~~~^^^^^^
TypeError: Base.__new__() takes 2 positional arguments but 3 were given
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
erlend-aasland
Awaiting requested review from erlend-aasland
erlend-aasland is a code owner
AA-Turner
Awaiting requested review from AA-Turner
AA-Turner is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.