summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/module.rst
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-05-04 17:56:58 (GMT)
committerBrett Cannon <brett@python.org>2013-05-04 17:56:58 (GMT)
commit4c14b5de1cf372e963a4378fc6cb2bca36d24eb8 (patch)
treec3d96e142fa3166f582414beeb53fd9792599345 /Doc/c-api/module.rst
parent4cfc0b5411354323433031b5e03862def2f00234 (diff)
downloadcpython-4c14b5de1cf372e963a4378fc6cb2bca36d24eb8.zip
cpython-4c14b5de1cf372e963a4378fc6cb2bca36d24eb8.tar.gz
cpython-4c14b5de1cf372e963a4378fc6cb2bca36d24eb8.tar.bz2
#17115,17116: Have modules initialize the __package__ and __loader__
attributes to None. The long-term goal is for people to be able to rely on these attributes existing and checking for None to see if they have been set. Since import itself sets these attributes when a loader does not the only instances when the attributes are None are from someone overloading __import__() and not using a loader or someone creating a module from scratch. This patch also unifies module initialization. Before you could have different attributes with default values depending on how the module object was created. Now the only way to not get the same default set of attributes is to circumvent initialization by calling ModuleType.__new__() directly.
Diffstat (limited to 'Doc/c-api/module.rst')
-rw-r--r--Doc/c-api/module.rst11
1 files changed, 9 insertions, 2 deletions
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst
index 65ff8fa..95a0169 100644
--- a/Doc/c-api/module.rst
+++ b/Doc/c-api/module.rst
@@ -35,13 +35,20 @@ There are only a few functions special to module objects.
single: __name__ (module attribute)
single: __doc__ (module attribute)
single: __file__ (module attribute)
+ single: __package__ (module attribute)
+ single: __loader__ (module attribute)
Return a new module object with the :attr:`__name__` attribute set to *name*.
- Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in;
- the caller is responsible for providing a :attr:`__file__` attribute.
+ The module's :attr:`__name__`, :attr:`__doc__`, :attr:`__package__`, and
+ :attr:`__loader__` attributes are filled in (all but :attr:`__name__` are set
+ to ``None``); the caller is responsible for providing a :attr:`__file__`
+ attribute.
.. versionadded:: 3.3
+ .. versionchanged:: 3.4
+ :attr:`__package__` and :attr:`__loader__` are set to ``None``.
+
.. c:function:: PyObject* PyModule_New(const char *name)