Skip to content

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

Closed
skirpichev wants to merge 3 commits into
python:mainfrom
skirpichev:fix-__prepare__-typo-114949
Closed

gh-114949: fix signature in the type.__prepare__() doc string#114950
skirpichev wants to merge 3 commits into
python:mainfrom
skirpichev:fix-__prepare__-typo-114949

Conversation

@skirpichev

@skirpichevskirpichev commented Feb 3, 2024

Copy link
Copy Markdown
Member

@skirpichev

Copy link
Copy Markdown
MemberAuthor

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

@JelleZijlstra

Copy link
Copy Markdown
Member

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

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

Which seems correct.

@AlexWaygood

AlexWaygood commented Sep 29, 2024

Copy link
Copy Markdown
Member

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 signaturereturn Signature.from_callable(obj, follow_wrapped=follow_wrapped,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/cpython/Lib/inspect.py", line 3108, in from_callablereturn _signature_from_callable(obj, sigcls=cls,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/cpython/Lib/inspect.py", line 2599, in _signature_from_callablereturn _signature_from_builtin(sigcls, obj,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alexw/dev/cpython/Lib/inspect.py", line 2398, in _signature_from_builtinraiseValueError("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
Copy Markdown
MemberAuthor

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 deleted the fix-__prepare__-typo-114949 branch September 30, 2024 02:26
Sign up for freeto 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

@skirpichev@JelleZijlstra@AlexWaygood