[Python-checkins] cpython: Actually initialize __main__.__loader__ with loader instances, not the
nick.coghlan
python-checkins at python.org
Sun Jul 15 11:10:50 CEST 2012
http://hg.python.org/cpython/rev/ba264b26d8d9
changeset: 78110:ba264b26d8d9
user: Nick Coghlan <ncoghlan at gmail.com>
date: Sun Jul 15 19:10:39 2012 +1000
summary:
Actually initialize __main__.__loader__ with loader instances, not the corresponding type objects
files:
Lib/test/test_cmd_line_script.py | 3 ++-
Python/pythonrun.c | 8 ++++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -37,7 +37,8 @@
assertEqual(result, ['Top level assignment', 'Lower level reference'])
# Check population of magic variables
assertEqual(__name__, '__main__')
-_loader = __loader__ if isinstance(__loader__, type) else type(__loader__)
+from importlib.machinery import BuiltinImporter
+_loader = __loader__ if __loader__ is BuiltinImporter else type(__loader__)
print('__loader__==%a' % _loader)
print('__file__==%a' % __file__)
assertEqual(__cached__, None)
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1355,11 +1355,15 @@
{
PyInterpreterState *interp;
PyThreadState *tstate;
- PyObject *loader;
+ PyObject *loader_type, *loader;
/* Get current thread state and interpreter pointer */
tstate = PyThreadState_GET();
interp = tstate->interp;
- loader = PyObject_GetAttrString(interp->importlib, loader_name);
+ loader_type = PyObject_GetAttrString(interp->importlib, loader_name);
+ if (loader_type == NULL) {
+ return -1;
+ }
+ loader = PyObject_CallFunction(loader_type, "ss", "__main__", filename);
if (loader == NULL ||
(PyDict_SetItemString(d, "__loader__", loader) < 0)) {
return -1;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list