<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks for the reply. CC'ing the mailing list.<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 9 Apr 2017, at 10:05, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" class="">ncoghlan@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 9 April 2017 at 16:13, Victor Varvariuc <<a href="mailto:victor.varvariuc@gmail.com" class="">victor.varvariuc@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class="">I think there are can be several ways to achieve the result.<br class=""><br class="">The question is if what I've presented is a valid concern. I think this would make the language more consistent and help reducing number of errors related to import without breaking old code.<br class=""><br class="">May I create an issue in the bug tracker?<br class=""></blockquote><br class="">Aye, go ahead - I would previously have advised against it, but given<br class="">at least one relatively low impact path to resolution, it's worth<br class="">filing it as an enhancement request.<br class=""><br class="">Cheers,<br class="">Nick.<br class=""><br class="">-- <br class="">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" class="">ncoghlan@gmail.com</a>   |   Brisbane, Australia<br class=""></div></div></blockquote></div><br class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">Begin forwarded message:</div><br class="Apple-interchange-newline"><div style="margin: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class="">Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" class="">ncoghlan@gmail.com</a>><br class=""></span></div><div style="margin: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Subject: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Re: [Python-ideas] Make `import a.b.c as m` is equivalent to `m = sys.modules['a.b.c']`</b><br class=""></span></div><div style="margin: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Date: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class="">9 April 2017 at 08:33:43 GMT+3<br class=""></span></div><div style="margin: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">To: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class="">Victor Varvariuc <<a href="mailto:victor.varvariuc@gmail.com" class="">victor.varvariuc@gmail.com</a>><br class=""></span></div><br class=""><div class="">On 8 April 2017 at 22:57, Victor Varvariuc <<a href="mailto:victor.varvariuc@gmail.com" class="">victor.varvariuc@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class="">Thanks, Nick, for the thorough explanation.<br class=""><br class="">changing those semantics isn't as<br class="">simple as just having the compiler reinterpret "import x.y.z as m" as<br class="">"from x.y import z as m"<br class=""><br class=""><br class="">I don't think this is a solution.<br class=""><br class="">The solution, IMO, is to treat  `import x.y.z as m` as `m =<br class="">__import__('x.y.z')` (or similar, IIRC).<br class=""></blockquote><br class="">That's not quite how the `__import__` hook works: when the fromlist is<br class="">empty, it returns the *base* module, not the most resolved one.<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">__import__("unittest.mock")<br class=""></blockquote></blockquote></blockquote>   <module 'unittest' from '/usr/lib64/python3.5/unittest/__init__.py'><br class=""><br class="">However, the idea does indicate a potential resolution, which would be<br class="">to add a new IMPORT_ATTR opcode with roughly the following semantics:<br class=""><br class="">   try:<br class="">       _op_result = getattr(obj, ATTR)<br class="">   except AttributeError:<br class="">       _package_name = obj.__package__<br class="">       if not _package_name:<br class="">           raise<br class="">       _op_result = sys.modules[_package_name + "." + ATTR]<br class=""><br class="">And then have the import statement unconditionally emit IMPORT_ATTR<br class="">instead of LOAD_ATTR for the "import x.* as y" case.<br class=""><br class="">Cheers,<br class="">Nick.<br class=""><br class="">-- <br class="">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" class="">ncoghlan@gmail.com</a>   |   Brisbane, Australia<br class=""></div></blockquote></div><div class=""><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><br class=""></div></div></body></html>