-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
docs are missing info about module attributes #64019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The docs for the inspect module and the types module do not list all the import-related module attributes. I'm guessing they've been out of sync a while. The docstring for for inspect.ismodule() is likewise missing information. |
Are they still missing? inspect.ismodule() seems to be there at least. |
As far as I can tell there is at least some information missing from the 'Types and members' section. Not all attributes are listed in the table. For example the attribute __cached__ is missing from the module type but it is documented in the inspect module. I can update the docs but I would rely on the comments in Lib/inspect.py on what to include. Executing inspect.getmembers on a module returns a lot more attributes than documented in ismodule. |
The relevant module attributes are described in the importlib docs: https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module |
I can help too. |
@emmanuel: thanks for offering your help. I made a first attempt at improving the docs in this branch: https://github.com/MichaelAnckaert/cpython/tree/bpo-19820 |
…butes instead of listing them (GH-98116) Co-authored-by: Michael Anckaert <michael.anckaert@sinax.be>
… attributes instead of listing them (pythonGH-98116) (cherry picked from commit 7d2dcc5) Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com> Co-authored-by: Michael Anckaert <michael.anckaert@sinax.be>
This is fixed in |
… attributes instead of listing them (pythonGH-98116) (cherry picked from commit 7d2dcc5) Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com> Co-authored-by: Michael Anckaert <michael.anckaert@sinax.be>
The
Honestly, we'd probably be best served by replacing the attributes in the (expand for a basic diff)diff --git a/Doc/library/types.rst b/Doc/library/types.rst
index 116868c24be..88bca9dba44 100644
--- a/Doc/library/types.rst
+++ b/Doc/library/types.rst
@@ -259,64 +259,7 @@ Standard names are defined for the following types:
The type of :term:`modules <module>`. The constructor takes the name of the
module to be created and optionally its :term:`docstring`.
-
- .. note::
- Use :func:`importlib.util.module_from_spec` to create a new module if you
- wish to set the various import-controlled attributes.
-
- .. attribute:: __doc__
-
- The :term:`docstring` of the module. Defaults to ``None``.
-
- .. attribute:: __loader__
-
- The :term:`loader` which loaded the module. Defaults to ``None``.
-
- This attribute is to match :attr:`importlib.machinery.ModuleSpec.loader`
- as stored in the :attr:`__spec__` object.
-
- .. note::
- A future version of Python may stop setting this attribute by default.
- To guard against this potential change, preferably read from the
- :attr:`__spec__` attribute instead or use
- ``getattr(module, "__loader__", None)`` if you explicitly need to use
- this attribute.
-
- .. versionchanged:: 3.4
- Defaults to ``None``. Previously the attribute was optional.
-
- .. attribute:: __name__
-
- The name of the module. Expected to match
- :attr:`importlib.machinery.ModuleSpec.name`.
-
- .. attribute:: __package__
-
- Which :term:`package` a module belongs to. If the module is top-level
- (i.e. not a part of any specific package) then the attribute should be set
- to ``''``, else it should be set to the name of the package (which can be
- :attr:`__name__` if the module is a package itself). Defaults to ``None``.
-
- This attribute is to match :attr:`importlib.machinery.ModuleSpec.parent`
- as stored in the :attr:`__spec__` object.
-
- .. note::
- A future version of Python may stop setting this attribute by default.
- To guard against this potential change, preferably read from the
- :attr:`__spec__` attribute instead or use
- ``getattr(module, "__package__", None)`` if you explicitly need to use
- this attribute.
-
- .. versionchanged:: 3.4
- Defaults to ``None``. Previously the attribute was optional.
-
- .. attribute:: __spec__
-
- A record of the module's import-system-related state. Expected to be an
- instance of :class:`importlib.machinery.ModuleSpec`.
-
- .. versionadded:: 3.4
-
+ See :ref:`import-mod-attrs` for module attributes.
.. data:: EllipsisType
Footnotes |
The change might not be that trivial: >>> import types
>>> dir(types.ModuleType('a'))
['__doc__', '__loader__', '__name__', '__package__', '__spec__'] So we really have those attributes, and not more I'd say by default. There is also a note saying:
I think the |
The issue has been fixed. Possible additional changes elsewhere should be new issues. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
inspect
docs link to module attributes instead of listing them (GH-98116) #99782inspect
docs link to module attributes instead of listing them (GH-98116) #99783The text was updated successfully, but these errors were encountered: