Repository navigation
gh-87613: Use AC vectorcall for weakref.ref() - #159470
Open
eendebakpt wants to merge 3 commits into
Open
eendebakpt wants to merge 3 commits into
eendebakpt wants to merge 3 commits into
Conversation
Convert weakref.ref.__new__ to Argument Clinic with the @vectorcall decorator so that creating a weak reference no longer builds an argument tuple that is then unpacked twice (by __new__ and by __init__), and so that the call can be specialized as CALL_BUILTIN_CLASS. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
It only validates the arguments that __new__ already consumed, so the generated parser replaces the PyArg_UnpackTuple call and the arity error message now matches the one from __new__. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Name the Argument Clinic class after tp_name (weakref.ReferenceType) so that the generated docstring's signature line is recognised, which makes help(weakref.ref) show the signature and inspect.signature() work. The argument errors now name ReferenceType instead of ref/__new__/__init__. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
cmaloney
approved these changes
Oct 15, 2026
cmaloney
left a comment
Contributor
There was a problem hiding this comment.
This looks good to me. Not a ton of usage but some in the import machinery which will help startup a bit. Have been looking at similar for some common decorators.
| @vectorcall | ||
| weakref.ReferenceType.__new__ as weakref_ref_new | ||
|
|
||
| ob: object |
Contributor
There was a problem hiding this comment.
nit: Should this be called "object" to match the docs https://docs.python.org/3/library/weakref.html#weakref.ref
Contributor
Author
There was a problem hiding this comment.
Hmm. This is positional only, so not too important but I think that would indeed be better.
Note: the subclass KeyedRef is not positional only, and uses the name ob.
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.
Convert
weakref.ref.__new__to Argument Clinic with the@vectorcalldecorator.weakref.ref.__init__, which only validates the arguments that__new__already consumed, is converted to Argument Clinic as well. This will also improve the signature ofweakref.ref.Benchmark script
Generated with help from Claude Code