mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #20383: Introduce importlib.util.module_from_spec().
Along the way, dismantle importlib._bootstrap._SpecMethods as it was no longer relevant and constructing the new function required partially dismantling the class anyway.
This commit is contained in:
parent
c8f0d6ebfc
commit
2a17bde930
17 changed files with 4536 additions and 4736 deletions
|
@ -1129,6 +1129,21 @@ an :term:`importer`.
|
|||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
.. function:: module_from_spec(spec)
|
||||
|
||||
Create a new module based on **spec**.
|
||||
|
||||
If the module object is from ``spec.loader.create_module()``, then any
|
||||
pre-existing attributes will not be reset. Also, no :exc:`AttributeError`
|
||||
will be raised if triggered while accessing **spec** or setting an attribute
|
||||
on the module.
|
||||
|
||||
This function is preferred over using :class:`types.ModuleType` to create a
|
||||
new module as **spec** is used to set as many import-controlled attributes on
|
||||
the module as possible.
|
||||
|
||||
.. versionadded:: 3.5
|
||||
|
||||
.. decorator:: module_for_loader
|
||||
|
||||
A :term:`decorator` for :meth:`importlib.abc.Loader.load_module`
|
||||
|
|
|
@ -115,6 +115,10 @@ Standard names are defined for the following types:
|
|||
The type of :term:`modules <module>`. 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``.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue