This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients brett.cannon, eric.snow, ezio.melotti, franck, ncoghlan
Date 2015-01-10.11:06:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420887983.7.0.14192013661.issue23203@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-01-10 11:06:23ncoghlansetrecipients: + ncoghlan, brett.cannon, ezio.melotti, eric.snow, franck
2015-01-10 11:06:23ncoghlansetmessageid: <1420887983.7.0.14192013661.issue23203@psf.upfronthosting.co.za>
2015-01-10 11:06:23ncoghlanlinkissue23203 messages
2015-01-10 11:06:23ncoghlancreate