[issue30024] Treat `import a.b.c as m` as `m = sys.modules['a.b.c']`

Nick Coghlan report at bugs.python.org
Tue Apr 11 08:09:13 EDT 2017


Nick Coghlan added the comment:

Huh, interesting - I'd missed that the only part of the "from a.b import c" that IMPORT_FROM implements is the LOAD_ATTR variant that falls back to sys.modules. The prior adjustment to get IMPORT_NAME to return "a.b" instead of "a" happens inside that opcode based on the fact that a non-empty from_list was passed in.

So indeed, there's no new opcode needed - as Serhiy points out, the compiler just needs to emit IMPORT_FROM instead of LOAD_ATTR for this case.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30024>
_______________________________________


More information about the Python-bugs-list mailing list