Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 83607:e39a8f8ceb9f
#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.
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Sat, 04 May 2013 13:56:58 -0400 |
| parents | 97522b189c79 |
| children | 0b34fd75b937 |
comparison
equal
deleted
inserted
replaced
| 83606:d4912244cce6 | 83607:e39a8f8ceb9f |
|---|---|
| 864 * False, but BuiltinImporter is still the most appropriate initial | 864 * False, but BuiltinImporter is still the most appropriate initial |
| 865 * setting for its __loader__ attribute. A more suitable value will | 865 * setting for its __loader__ attribute. A more suitable value will |
| 866 * be set if __main__ gets further initialized later in the startup | 866 * be set if __main__ gets further initialized later in the startup |
| 867 * process. | 867 * process. |
| 868 */ | 868 */ |
| 869 if (PyDict_GetItemString(d, "__loader__") == NULL) { | 869 PyObject *loader = PyDict_GetItemString(d, "__loader__"); |
| 870 if (loader == NULL || loader == Py_None) { | |
| 870 PyObject *loader = PyObject_GetAttrString(interp->importlib, | 871 PyObject *loader = PyObject_GetAttrString(interp->importlib, |
| 871 "BuiltinImporter"); | 872 "BuiltinImporter"); |
| 872 if (loader == NULL) { | 873 if (loader == NULL) { |
| 873 Py_FatalError("Failed to retrieve BuiltinImporter"); | 874 Py_FatalError("Failed to retrieve BuiltinImporter"); |
| 874 } | 875 } |
