Skip to content

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

Merged
JelleZijlstra merged 3 commits into
python:mainfrom
tonghuaroot:fix-typerepr-builtin-module
Oct 12, 2026
Merged

JelleZijlstra merged 3 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
@JelleZijlstra JelleZijlstra added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Jul 10, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Oct 11, 2026
@JelleZijlstra
JelleZijlstra enabled auto-merge (squash) October 12, 2026 23:09
@JelleZijlstra
JelleZijlstra merged commit 6979003 into python:main Oct 12, 2026
52 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @tonghuaroot for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 12, 2026

Copy link
Copy Markdown

GH-159280 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 12, 2026
@bedevere-app

bedevere-app Bot commented Oct 12, 2026

Copy link
Copy Markdown

GH-159281 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 12, 2026
encukou pushed a commit that referenced this pull request Oct 13, 2026
…thods (GH-152693) (GH-159280)

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.
(cherry picked from commit 6979003)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
JelleZijlstra pushed a commit that referenced this pull request Oct 14, 2026
…thods (GH-152693) (#159281)

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

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.
(cherry picked from commit 6979003)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants