New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-103131: Convert sys.set_asyncgen_hooks
to AC
#103132
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the help() output for these functions?
@@ -0,0 +1,2 @@ | |||
Convert :func:`sys.getsizeof` and :func:`sys.set_asyncgen_hooks` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an internal refactoring. Such changes usually are not reflected in the NEWS file.
Hm, indeed >>> import sys
>>> help(sys.getsizeof)
Help on built-in function getsizeof in module sys:
getsizeof(...)
getsizeof(object [, default]) -> int
Return the size of object in bytes.
>>> help(sys.set_asyncgen_hooks)
Help on built-in function set_asyncgen_hooks in module sys:
set_asyncgen_hooks(...)
set_asyncgen_hooks(* [, firstiter] [, finalizer])
Set a finalizer for async generators objects. After: >>> import sys
>>> help(sys.getsizeof)
Help on built-in function getsizeof in module sys:
getsizeof(...)
Return the size of object in bytes.
>>> help(sys.set_asyncgen_hooks)
Help on built-in function set_asyncgen_hooks in module sys:
set_asyncgen_hooks(...)
Set a finalizer for async generators objects.
>>> sys.getsizeof.__text_signature__
'($module, /, object, default=<unrepresentable>)'
>>> sys.set_asyncgen_hooks
<built-in function set_asyncgen_hooks>
>>> sys.set_asyncgen_hooks.__text_signature__
'($module, /, firstiter=<unrepresentable>,\n finalizer=<unrepresentable>)' Looks like >>> inspect.signature(sys.getsizeof)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 3322, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 3066, in from_callable
return _signature_from_callable(obj, sigcls=cls,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 2558, in _signature_from_callable
return _signature_from_builtin(sigcls, obj,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 2359, in _signature_from_builtin
return _signature_fromstr(cls, func, s, skip_bound_arg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sobolev/Desktop/cpython/Lib/inspect.py", line 2220, in _signature_fromstr
raise ValueError("{!r} builtin has invalid signature".format(obj))
ValueError: <built-in function getsizeof> builtin has invalid signature This part also looks strange:
Why In |
Ok, I've found the temporary solution. Other similar cases just copy the signature into the docs: Line 1072 in 20c0f19
New help with it:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now has merge conflicts
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Python/sysmodule.c
Outdated
firstiter: object = NULL | ||
finalizer: object = NULL | ||
|
||
set_asyncgen_hooks(* [, firstiter] [, finalizer]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the doc should be modified to use this signature: https://docs.python.org/dev/library/sys.html#sys.set_asyncgen_hooks
Or this docstring should use the doc signature: sys.set_asyncgen_hooks(firstiter, finalizer)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs also read:
Accepts two optional keyword arguments [...]
IMO, the signature in the docs should be updated to reflect the actual implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #114385
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rebase your PR on top of it? There are now merge conflicts.
The help now shows the signature twice. Please remove the second signature:
|
Python/sysmodule.c
Outdated
sys.getsizeof | ||
|
||
object: object | ||
default as dflt: object = NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use a longer name rather than a shorter one:
default as dflt: object = NULL | |
default as default_size: object = NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make the diff unnecessary bigger. IMO, it is better to align with the current naming.
The |
sys.getsizeof
and sys.set_asyncgen_hooks
to ACsys.set_asyncgen_hooks
to AC
Here's the new » ./python.exe
Python 3.13.0a5+ (heads/issue-103131:c0086505210, Mar 20 2024, 13:48:58) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> help(sys.set_asyncgen_hooks)
Help on built-in function set_asyncgen_hooks in module sys:
set_asyncgen_hooks(firstiter=None, finalizer=None)
Set a finalizer for async generators objects.
Lines 1766 to 1790 in 8182319
So, this now should be a simple change :) |
Ok, I've found this branch:
Looks like this PR is not correct either. It is better to close it. |
If someone wants to continue the work, I suggest to leave Argument Clinic aside, and start by fixing the implementation and the signature to prepare the API for Argument Clinic. |
Refs #11328
CC @taleinat @serhiy-storchaka as in the original PR
sys.getsizeof
andsys.set_asyncgen_hooks
are not converted to AC #103131