Skip to content

gh-114949: fix signature in the type.__prepare__() doc string #114950

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

Closed

Conversation

skirpichev
Copy link
Member

@skirpichev skirpichev commented Feb 3, 2024

@skirpichev
Copy link
Member Author

Probably could skip news. Not sure if it worth to add also a regression test.

@JelleZijlstra
Copy link
Member

What is the problem this solves? On main I see:

>>> inspect.signature(type.__prepare__)
<Signature (name, bases, /, **kwds)>

Which seems correct.

@AlexWaygood
Copy link
Member

AlexWaygood commented Sep 29, 2024

I believe the problem described by #114949 (comment) was solved by

commit 1d75ef6b6186619081c166b21c71c15b4f98beb8
Author: Serhiy Storchaka <storchaka@gmail.com>
Date:   Mon Nov 13 09:13:49 2023 +0200

    gh-111999: Add signatures and improve docstrings for builtins (GH-112000)

 Lib/test/test_inspect/test_inspect.py | 11 +++++---
 Objects/boolobject.c                  |  5 ++--
 Objects/descrobject.c                 |  3 +++
 Objects/funcobject.c                  |  6 +++--
 Objects/setobject.c                   | 48 +++++++++++++++++++++++------------
 Objects/typeobject.c                  |  6 +++--
 Objects/unicodeobject.c               | 12 +++++----
 Python/bltinmodule.c                  | 22 +++++++++-------
 8 files changed, 74 insertions(+), 39 deletions(-)

On Python 3.12, and on the main branch prior to 1d75ef6, we see this behaviour:

~/dev/cpython (d0058cbd1cd) % ./python.exe -c "import inspect; print(inspect.signature(type.__prepare__))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import inspect; print(inspect.signature(type.__prepare__))
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexw/dev/cpython/Lib/inspect.py", line 3366, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexw/dev/cpython/Lib/inspect.py", line 3108, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexw/dev/cpython/Lib/inspect.py", line 2599, in _signature_from_callable
    return _signature_from_builtin(sigcls, obj,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexw/dev/cpython/Lib/inspect.py", line 2398, in _signature_from_builtin
    raise ValueError("no signature found for builtin {!r}".format(func))
ValueError: no signature found for builtin <built-in method __prepare__ of type object at 0x100eae0e0>

On 1d75ef6 and subsequent commits, we see this:

~/dev/cpython (1d75ef6b618) % ./python.exe -c "import inspect; print(inspect.signature(type.__prepare__))"

Although I see you were a reviewer for #112000, @skirpichev, and you filed this PR after that one was merged. So maybe that isn't actually the problem you're describing in #114949 (comment)?

@skirpichev
Copy link
Member Author

Indeed, now fixed in the main. I'll close this (and issue).

Note, however, that

$ git grep '$cls' Objects Modules/
Objects/typeobject.c:     PyDoc_STR("__prepare__($cls, name, bases, /, **kwds)\n"
$ git grep '$type' Objects/ Modules/
Objects/clinic/bytearrayobject.c.h:"fromhex($type, string, /)\n"
Objects/clinic/bytesobject.c.h:"fromhex($type, string, /)\n"
Objects/clinic/complexobject.c.h:"from_number($type, number, /)\n"
Objects/clinic/dictobject.c.h:"fromkeys($type, iterable, value=None, /)\n"
Objects/clinic/floatobject.c.h:"fromhex($type, string, /)\n"
Objects/clinic/floatobject.c.h:"from_number($type, number, /)\n"
Objects/clinic/floatobject.c.h:"__getformat__($type, typestr, /)\n"
Objects/clinic/longobject.c.h:"from_bytes($type, /, bytes, byteorder=\'big\', *, signed=False)\n"
Objects/clinic/memoryobject.c.h:"_from_flags($type, /, object, flags)\n"
Objects/clinic/odictobject.c.h:"fromkeys($type, /, iterable, value=None)\n"
Objects/typeobject.c:            return "($type, /)";
Objects/typeobject.c:            return "($type, object, /)";
Objects/typeobject.c:     PyDoc_STR("__new__($type, *args, **kwargs)\n--\n\n"
Modules/_decimal/docstrings.h:"from_float($type, f, /)\n--\n\n\
Modules/_multiprocessing/clinic/semaphore.c.h:"_rebuild($type, handle, kind, maxvalue, name, /)\n"
Modules/_testcapi/docstring.c:            "classmeth($type, /, a, b=<x>)\n"
Modules/clinic/_datetimemodule.c.h:"fromtimestamp($type, timestamp, /)\n"
Modules/clinic/_datetimemodule.c.h:"now($type, /, tz=None)\n"
Modules/clinic/_zoneinfo.c.h:"from_file($type, file_obj, /, key=None)\n"
Modules/clinic/_zoneinfo.c.h:"no_cache($type, /, key)\n"
Modules/clinic/_zoneinfo.c.h:"clear_cache($type, /, *, only_keys=None)\n"
Modules/clinic/_zoneinfo.c.h:"_unpickle($type, key, from_cache, /)\n"
Modules/clinic/itertoolsmodule.c.h:"from_iterable($type, iterable, /)\n"
Modules/clinic/selectmodule.c.h:"fromfd($type, fd, /)\n"
Modules/clinic/selectmodule.c.h:"fromfd($type, fd, /)\n"

@skirpichev skirpichev closed this Sep 30, 2024
@skirpichev skirpichev deleted the fix-__prepare__-typo-114949 branch September 30, 2024 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants