Skip to content

gh-152692: Fix annotationlib.type_repr() for bound built-in methods#152693

Open
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:fix-typerepr-builtin-module
Open

gh-152692: Fix annotationlib.type_repr() for bound built-in methods#152693
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:fix-typerepr-builtin-module

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

type_repr() returned a string naming a nonexistent module None -- e.g.
type_repr([].append) == 'None.list.append' -- for bound built-in methods,
whose __module__ is None.

Return the qualified name when __module__ is None, as already done for the
"builtins" module. This also covers C-accelerator functions such as
random.random. annotations_to_string and
get_annotations(format=Format.STRING) are fixed transitively when an
annotation value is such a method.

…hods

type_repr() returned a string naming a nonexistent module None -- e.g.
type_repr([].append) == 'None.list.append' -- for bound built-in methods,
whose __module__ is None.

Return the qualified name when __module__ is None, as already done for the
"builtins" module.

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect for extension classes that are not in the builtins module.

>>> print(datetime.datetime.now().isoformat.__module__)
None

@bedevere-app

bedevere-app Bot commented Jul 6, 2026

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@tonghuaroot

Copy link
Copy Markdown
Contributor Author

Good catch. When __module__ is None I now recover the real module from __self__, so extension-type methods like datetime.datetime.isoformat keep their module.

I have made the requested changes; please review again

@bedevere-app

bedevere-app Bot commented Jul 7, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@sobolevn, @JelleZijlstra: please review the changes made to this pull request.

@bedevere-app bedevere-app Bot requested review from JelleZijlstra and sobolevn July 7, 2026 02:32
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