Skip to content

Documentation for __module__ #139842

@pawamoy

Description

@pawamoy

Documentation

The __module__ attribute doesn't have a proper entry in the docs. It is only documented in the context of specific object types, as an attribute. Would it make sense to give its own entry?

Moreover, its description is inconsistent across the documentation:

Attribute Description Suggestion
definition.__module__ The name of the module in which a class or function was defined. Add "or None if unavailable"?
function.__module__ The name of the module the function was defined in, or None if unavailable. ✔️
method.__module__ The name of the module the method was defined in, or None if unavailable. ✔️
type.__module__ The name of the module in which the class was defined. Add "or None if unavailable`?
typing.NewType.__module__ The module in which the new type is defined. Say "the name of the module", add "or None if unavailable"?
typing.TypeAliasType.__module__ The module in which the type alias was defined: Say "the name of the module", add "or None if unavailable"?

(links found via this search: https://docs.python.org/3/search.html?q=__module__)

I come from this issue mkdocstrings/griffe#419, where a user reports that the __module__ attribute of an object seems to be an actual instance of module rather than just its (qualified) name, and I wonder if someone made a mistake when creating the object dynamically due to the docs being unclear.

Also, and more importantly, I just wanted to make sure what the specification is, whether __module__ should only ever be a string or None, or can be a module instance. The description for NewType and TypeAliasType make it seem like it can be a module.

Happy to send a PR to normalize the descriptions 🙂

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions