Skip to content

Empty __module__ attribute for built-in static methods #115231

Description

@skirpichev

Bug report

Bug description:

An example:

>>> bytes.maketrans.__module__isNone
True

c.f. pure-python staticmethod:

>>> classSpam:
... @staticmethod
... deffoo():
... 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__isNone
True

Probably this should be fixed as well.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions