Skip to content

Commit fd67e0a

Browse files
committed
Improve types.ModuleType docs and some deprecation notes
1 parent 9cf64d3 commit fd67e0a

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Doc/library/types.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,18 @@ Standard names are defined for the following types:
260260
The type of :term:`modules <module>`. The constructor takes the name of the
261261
module to be created and optionally its :term:`docstring`.
262262

263-
See :ref:`documentation on module objects <module-objects>` for details
264-
on the special attributes that can be found on instances of
265-
:class:`!ModuleType`.
263+
.. seealso::
264+
265+
:ref:`Documentation on module objects <module-objects>`
266+
Provides details on the special attributes that can be found on
267+
instances of :class:`!ModuleType`.
268+
269+
:func:`importlib.util.module_from_spec`
270+
Modules created using the :class:`!ModuleType` constructor are
271+
created with many of their special attributes unset or set to default
272+
values. :func:`!module_from_spec` provides a more robust way of
273+
creating :class:`!ModuleType` instances which ensures the various
274+
attributes are set appropriately.
266275

267276
.. data:: EllipsisType
268277

Doc/reference/datamodel.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,10 +1028,10 @@ this approach.
10281028
Previously the attribute was optional.
10291029

10301030
.. deprecated-removed:: 3.12 3.14
1031-
The value of :attr:`!module__loader__` is expected to be the same as
1032-
:attr:`__spec__.loader <importlib.machinery.ModuleSpec.loader>`.
1033-
The use of :attr:`!module.__loader__` is deprecated and slated for
1034-
removal in Python 3.14.
1031+
Setting :attr:`!__loader__` on a module while failing to set
1032+
:attr:`!__spec__.loader` is deprecated. In Python 3.14,
1033+
:attr:`!module.__loader__` will cease to be set or taken into
1034+
consideration by the import system or the standard library.
10351035

10361036
.. attribute:: module.__path__
10371037

@@ -1077,8 +1077,10 @@ this approach.
10771077
instead of :attr:`!module.__cached__`.
10781078

10791079
.. deprecated-removed:: 3.13 3.15
1080-
:attr:`!__cached__` will cease to be set or taken into consideration
1081-
by the import system or standard library.
1080+
Setting :attr:`!__cached__` on a module while failing to set
1081+
:attr:`!__spec__.cached` is deprecated. In Python 3.15,
1082+
:attr:`!__cached__` will cease to be set or taken into consideration by
1083+
the import system or standard library.
10821084

10831085
Other writable attributes on module objects
10841086
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)