◐ Shell
clean mode source ↗

gh-103131: Convert `sys.set_asyncgen_hooks` to AC by sobolevn · Pull Request #103132 · python/cpython

Hm, indeed help has gotten even worse. Before:

>>> 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 cannot parse <unrepresentable> as a part of the signature.

>>> 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:

'($module, /, firstiter=<unrepresentable>,\n                   finalizer=<unrepresentable>)'

Why \n ?

In typeshed we use ... for default values that are hard / impossible to represent.
Can we use the same technique here? So, __text_signature__ would become '($module, /, firstiter=..., finalizer=...)'