summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
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
commit0010471202cc1a3eff955f556a247c78e7e2c34b (patch)
treeca673344224a5e032780021f093b5a08231d79f6 /Python/pythonrun.c
parent0c4865353d2398673cbdabc179c76e3caff4322c (diff)
downloadcpython-0010471202cc1a3eff955f556a247c78e7e2c34b.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 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index b92a8bd9b4..40f6ab4cee 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -866,7 +866,8 @@ initmain(PyInterpreterState *interp)
* be set if __main__ gets further initialized later in the startup
* process.
*/
- if (PyDict_GetItemString(d, "__loader__") == NULL) {
+ PyObject *loader = PyDict_GetItemString(d, "__loader__");
+ if (loader == NULL || loader == Py_None) {
PyObject *loader = PyObject_GetAttrString(interp->importlib,
"BuiltinImporter");
if (loader == NULL) {