GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Empty __module__ attribute for built-in static methods · Issue #115231 · python/cpython

Empty __module__ attribute for built-in static methods #115231

New issue
Copy link
New issue
Copy link
Closed
Closed
Empty __module__ attribute for built-in static methods#115231
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@skirpichev
skirpichev
opened on Feb 10, 2024
Issue body actions

Bug report

Bug description:

An example:

>>> bytes.maketrans.__module__ is None
True

c.f. pure-python staticmethod:

>>> class Spam:
...     @staticmethod
...     def foo():
...         pass
... 
>>> Spam.foo.__module__
'__main__'

I'm not sure, maybe this should be treated rather as a feature request. Docs says about the attribute value: "The name of the module the function was defined in, or None if unavailable." But clearly, this value is available: the type_add_method() has type argument and we could query value of its __module__ attribute.

Edit: BTW, same happens for class methods, e.g.:

>>> int.from_bytes.__module__ is None
True

Probably this should be fixed as well.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

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

Activity

  1. skirpichev
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Feb 10, 2024
  2. skirpichev
    added a commit that references this issue on Feb 10, 2024

    pythongh-115231: fill __module__ attribute for built-in staticmethods

    9b31877
  3. skirpichev
    added a commit that references this issue on Feb 26, 2024

    pythongh-115231: fill __module__ for built-in class/staticmethods

    ff758ab
  4. skirpichev
    added a commit that references this issue on Jul 19, 2024

    Revert "pythongh-115231: fill __module__ for built-in class/staticmet…

    38b7d53
  5. serhiy-storchaka commented on Nov 2, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Nov 2, 2024
    Member
    More actions

    Built-in static and class methods has different types than static and class methods in Python classes. This is not a bug.

    Static and class methods in Python classes started to inherit function attributes only since 3.10 (bpo-43682/gh-87848). cc @vstinner

  6. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.14bugs and security fixesbugs and security fixes
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Nov 2, 2024
  7. skirpichev commented on Nov 2, 2024

    @skirpichev
    skirpichev
    on Nov 2, 2024
    MemberAuthor
    More actions

    Static and class methods in Python classes started to inherit function attributes only since 3.10

    Hmm, above code snippet works on 3.8+ as well, e.g.:

    Python 3.9.19+ (heads/3.9:3f5d9d12c7, Aug 29 2024, 13:17:09) 
    [GCC 12.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class Spam:
    ...     @staticmethod
    ...     def foo():
    ...         pass
    ... 
    >>> Spam.foo.__module__
    '__main__'
    >>> 
  8. serhiy-storchaka commented on Nov 2, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Nov 2, 2024
    Member
    More actions

    Static and class methods in Python classes copy attributes from the wrapped methods. But unbound built-in methods do not have the __module__ attribute, so not copying it is okay. On other hand, bound built-in methods have __module__ equal to None:

    >>> collections.deque.append.__module__
    Traceback (most recent call last):
      File "<python-input-15>", line 1, in <module>
        collections.deque.append.__module__
    AttributeError: 'method_descriptor' object has no attribute '__module__'. Did you mean: '__reduce__'?
    >>> collections.deque().append.__module__ is None
    True

    We should first decide whether we need the __module__ attribute for regular builtin methods.

  9. skirpichev commented on Nov 2, 2024

    @skirpichev
    skirpichev
    on Nov 2, 2024
    MemberAuthor
    More actions

    We should first decide whether we need the __module__ attribute for regular builtin methods.

    That should be helpful for introspection. E.g. now the inspect._signature_fromstr() resolves module_dict to empty for e.g. bytes.maketrans() or int.from_bytes(). That essentially forbids e.g. using module constants as default values.

  10. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    and removed
    3.14bugs and security fixesbugs and security fixes
    on Dec 15, 2024
  11. skirpichev
    assigned
    skirpichev
    and unassigned
    skirpichev
    on Sep 9, 2025
  12. skirpichev
    self-assigned this
    on Oct 14, 2025
  13. skirpichev
    removed their assignment
    on Oct 27, 2025
  14. vstinner
    added a commit that references this issue on Feb 2, 2026

    gh-115231: Fill __module__ for built-in staticmethods (#115232)

    15c9f24
  15. Aniketsy
    added a commit that references this issue on Feb 3, 2026

    pythongh-115231: Fill __module__ for built-in staticmethods (python#1…

    a09aa1e
  16. thunder-coding
    added a commit that references this issue on Feb 15, 2026

    pythongh-115231: Fill __module__ for built-in staticmethods (python#1…

    3e81347
  17. hugovk
    closed this as completedon Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.