Repository navigation
Conversation
…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 <noreply@anthropic.com>
Contributor
Author
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
tp_newslot 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_namewould be slightly faster to use it includes the module name like_thread.RLock()which adds confusion. Use_PyType_Name(type)which returnsRLock(). 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
frozensetto Argument Clinic I think in general it makes these error messages a little better for new.