[Python-checkins] cpython: Issue #17907: Document types.ModuleType's constructor and attributes,

brett.cannon python-checkins at python.org
Sat Jun 15 01:20:06 CEST 2013


http://hg.python.org/cpython/rev/be50f1403f4d
changeset: 84129:be50f1403f4d
user: Brett Cannon <brett at python.org>
date: Fri Jun 14 19:19:57 2013 -0400
summary:
 Issue #17907: Document types.ModuleType's constructor and attributes,
allowing for documenting imp.new_module() as deprecated.
files:
 Doc/library/imp.rst | 3 +++
 Doc/library/types.rst | 30 ++++++++++++++++++++++++++++--
 Misc/NEWS | 3 +++
 3 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/Doc/library/imp.rst b/Doc/library/imp.rst
--- a/Doc/library/imp.rst
+++ b/Doc/library/imp.rst
@@ -112,6 +112,9 @@
 Return a new empty module object called *name*. This object is *not* inserted
 in ``sys.modules``.
 
+ .. deprecated:: 3.4
+ Use :class:`types.ModuleType` instead.
+
 
 .. function:: reload(module)
 
diff --git a/Doc/library/types.rst b/Doc/library/types.rst
--- a/Doc/library/types.rst
+++ b/Doc/library/types.rst
@@ -107,9 +107,35 @@
 C".)
 
 
-.. data:: ModuleType
+.. class:: ModuleType(name, doc=None)
 
- The type of modules.
+ The type of :term:`modules <module>`. Constructor takes the name of the
+ module to be created and optionally its :term:`docstring`.
+
+ .. attribute:: __doc__
+
+ The :term:`docstring` of the module. Defaults to ``None``.
+
+ .. attribute:: __loader__
+
+ The :term:`loader` which loaded the module. Defaults to ``None``.
+
+ .. versionchanged:: 3.4
+ Defaults to ``None``. Previously the attribute was optional.
+
+ .. attribute:: __name__
+
+ The name of the module.
+
+ .. 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``.
+
+ .. versionchanged:: 3.4
+ Defaults to ``None``. Previously the attribute was optional.
 
 
 .. data:: TracebackType
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -123,6 +123,9 @@
 Library
 -------
 
+- Issue #17907: Document imp.new_module() as deprecated in favour of
+ types.ModuleType.
+
 - Issue #18192: Introduce importlib.util.MAGIC_NUMBER and document as deprecated
 imp.get_magic().
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /