Skip to content

gh-115231: fill __module__ for built-in staticmethods - #115232

Merged
vstinner merged 17 commits into
python:mainfrom
skirpichev:static-bltin-__module__-115231
Feb 2, 2026
Merged

gh-115231: fill __module__ for built-in staticmethods#115232
vstinner merged 17 commits into
python:mainfrom
skirpichev:static-bltin-__module__-115231

Conversation

@skirpichev

@skirpichevskirpichev commented Feb 10, 2024

Copy link
Copy Markdown
Member

Comment threadLib/test/test_funcattrs.py
Comment threadObjects/typeobject.c Outdated
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@skirpichev
skirpichevforce-pushed the static-bltin-__module__-115231 branch from 8d2f05d to be1c7efCompareFebruary 10, 2024 13:40
@Eclips4Eclips4 mentioned this pull request Feb 10, 2024
@skirpichevskirpichev changed the title gh-115231: fill __module__ attribute for built-in staticmethodsgh-115231: fill __module__ for built-in class/staticmethodsFeb 11, 2024
@skirpichev
skirpichevforce-pushed the static-bltin-__module__-115231 branch from 28eec6f to c4dec10CompareFebruary 11, 2024 03:25
@skirpichev

Copy link
Copy Markdown
MemberAuthor

See also #82062: we could fix that issue in a similar approach, using __objclass__.__module__ to set the __module__ attribute. Right now for built-in instance methods its missing (c.f. pure-python classes):

>>> int.to_bytes.__module__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'method_descriptor' object has no attribute '__module__'. Did you mean: '__reduce__'?

@skirpichev

Copy link
Copy Markdown
MemberAuthor

CC @serhiy-storchaka

Comment threadObjects/typeobject.c Outdated
Comment threadObjects/descrobject.c Outdated
@skirpichev
skirpichev marked this pull request as draft November 2, 2024 13:23
@skirpichev
skirpichev marked this pull request as ready for review February 24, 2025 08:36
@skirpichev
skirpichevforce-pushed the static-bltin-__module__-115231 branch from d29c90d to 386f383CompareSeptember 9, 2025 05:36
@skirpichevskirpichev changed the title gh-115231: fill __module__ for built-in class/staticmethodsgh-115231: fill __module__ for built-in staticmethodsSep 9, 2025

@serhiy-storchakaserhiy-storchaka 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.

LGTM. But I would look what can we do with unbound instance methods and class methods. Because providing __module__ only for static methods loses purpose.

@skirpichev

Copy link
Copy Markdown
MemberAuthor

class methods

Hmm, I don't see ways to speedup this. Maybe solution is just to pay this price at time of access the __module__ attribute.

only for static methods loses purpose

Why? Something meaningful is better than just None.

@skirpichev

Copy link
Copy Markdown
MemberAuthor

CC @vstinner

Comment threadObjects/typeobject.c Outdated
Comment threadLib/test/test_funcattrs.py
Co-authored-by: Victor Stinner <vstinner@python.org>

@vstinnervstinner 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.

LGTM

@vstinner

Copy link
Copy Markdown
Member

I clicked on [Update branch] since this PR was created many months ago.

@vstinner
vstinner merged commit 15c9f24 into python:mainFeb 2, 2026
47 checks passed
@skirpichev
skirpichev deleted the static-bltin-__module__-115231 branch February 2, 2026 11:36
Aniketsy pushed a commit to Aniketsy/cpython that referenced this pull request Feb 3, 2026
…15232)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
…15232)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@skirpichev@vstinner@serhiy-storchaka@sobolevn@nazeerali4325-commits