Nick Coghlan added the comment: I'm suggesting we change this part of the bytecode emitted for "import x.y.z as bar":
6 IMPORT_NAME 0 (x.y.z) 9 LOAD_ATTR 1 (y) 12 LOAD_ATTR 2 (z) 15 STORE_NAME 3 (bar) to instead emit: 6 IMPORT_NAME 0 (x.y) 9 IMPORT_FROM 1 (z) 12 STORE_NAME 2 (bar) 15 POP_TOP The degenerate case of "import x as y" would be unchanged, only cases which currently emit LOAD_ATTR instructions would be modified. I haven't looked at the practical details yet, but the key would be to use IMPORT_FROM to do the name resolution, rather than LOAD_ATTR, thus enabling the fallback to sys.modules for the eager lookup. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23203> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com