summaryrefslogtreecommitdiff
path: root/Lib/doctest.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-05-04 13:56:58 -0400
committerBrett Cannon <brett@python.org>2013-05-04 13:56:58 -0400
commit4c14b5de1cf372e963a4378fc6cb2bca36d24eb8 (patch)
treec3d96e142fa3166f582414beeb53fd9792599345 /Lib/doctest.py
parent4cfc0b5411354323433031b5e03862def2f00234 (diff)
downloadcpython-git-4c14b5de1cf372e963a4378fc6cb2bca36d24eb8.tar.gz
#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 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 16a732d037..1b8a9d4fe8 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -215,7 +215,7 @@ def _load_testfile(filename, package, module_relative, encoding):
if module_relative:
package = _normalize_module(package, 3)
filename = _module_relative_path(package, filename)
- if hasattr(package, '__loader__'):
+ if getattr(package, '__loader__', None) is not None:
if hasattr(package.__loader__, 'get_data'):
file_contents = package.__loader__.get_data(filename)
file_contents = file_contents.decode(encoding)