]> granicus.if.org Git - python/commit
#17115,17116: Have modules initialize the __package__ and __loader__
authorBrett Cannon <brett@python.org>
Sat, 4 May 2013 17:56:58 +0000 (13:56 -0400)
committerBrett Cannon <brett@python.org>
Sat, 4 May 2013 17:56:58 +0000 (13:56 -0400)
commit4c14b5de1cf372e963a4378fc6cb2bca36d24eb8
treec3d96e142fa3166f582414beeb53fd9792599345
parent4cfc0b5411354323433031b5e03862def2f00234
#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.
15 files changed:
Doc/c-api/module.rst
Doc/library/importlib.rst
Doc/reference/import.rst
Doc/whatsnew/3.4.rst
Lib/ctypes/test/__init__.py
Lib/doctest.py
Lib/importlib/_bootstrap.py
Lib/inspect.py
Lib/test/test_descr.py
Lib/test/test_importlib/test_api.py
Lib/test/test_module.py
Misc/NEWS
Objects/moduleobject.c
Python/importlib.h
Python/pythonrun.c