<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 18 Jun 2017, at 19:21, Barry Scott <<a href="mailto:barry@barrys-emacs.org" class="">barry@barrys-emacs.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On 14 Jun 2017, at 07:33, 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 14 June 2017 at 13:02, Mahmoud Hashemi <<a href="mailto:mahmoud@hatnote.com" class="">mahmoud@hatnote.com</a>> wrote:<br class=""><blockquote type="cite" class="">That would be amazing! If there's anything I can do to help make that<br class="">happen, please let me know. It'll almost certainly save that much time for<br class="">me alone down the line, anyway :)<br class=""></blockquote><br class="">The `IMPORT_FROM` opcode's error handling would probably be the best<br class="">place to start poking around:<br class=""><a href="https://github.com/python/cpython/blob/master/Python/ceval.c#L5055" class="">https://github.com/python/cpython/blob/master/Python/ceval.c#L5055</a><br class=""><br class="">If you can prove the concept there, that would:<br class=""><br class="">1. Directly handle the "from x import y" and "import x.y as name" cases<br class="">2. Provide a starting point for factoring out a "report missing module<br class="">attribute" helper that could be shared with ModuleType<br class=""><br class="">As an example of querying _frozen_importlib state from C code, I'd<br class="">point to<span class="Apple-converted-space"> </span><a href="https://github.com/python/cpython/blob/master/Python/import.c#L478" class="">https://github.com/python/cpython/blob/master/Python/import.c#L478</a><br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">I had thought that the solution would be in the .py implementation of the import</div><div class="">machinery not in the core C code.</div><div class=""><br class=""></div><div class="">I was going to simply keep track of the names of the modules that are being imported</div><div class="">and raise an exception if an import attempted to import a module that had not completed</div><div class="">being imported. It seems from a quick loom at the code that this would be practical.</div><div class=""><br class=""></div><div class="">Are you saying that there is a subtle point about import and detection of cycles that</div><div class="">means the work must be done in C?</div></div></div></blockquote><div><br class=""></div><div>It seemed that PyImport_ImportModuleLevelObject() always calls out the</div><div>interp->importlib. For example:</div><div><div><br class=""></div><div>                value = _PyObject_CallMethodIdObjArgs(interp->importlib,</div><div>                                                &PyId__lock_unlock_module, abs_name,</div><div>                                                NULL);</div><div><br class=""></div><div>Where interp->importlib is the frozen importlib.py code I thought.</div></div><div><br class=""></div><div>I'd assumed that I would need to change the importlib.py code and</div><div>build that as the frozen version to implement this.</div><div><br class=""></div><div>Barry</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><div class="">Barry</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">Cheers,<br class="">Nick.<br class=""><br class="">P.S. I also double checked that ImportError & AttributeError have<br class="">compatible binary layouts, so dual inheritance from them works :)<br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" class="">ncoghlan@gmail.com</a><span class="Apple-converted-space"> </span>  |   Brisbane, Australia<br class="">_______________________________________________<br class="">Python-ideas mailing list<br class=""><a href="mailto:Python-ideas@python.org" class="">Python-ideas@python.org</a><br class=""><a href="https://mail.python.org/mailman/listinfo/python-ideas" class="">https://mail.python.org/mailman/listinfo/python-ideas</a><br class="">Code of Conduct: http://python.org/psf/codeofconduct/<br class=""><br class=""></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Python-ideas mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:Python-ideas@python.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">Python-ideas@python.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://mail.python.org/mailman/listinfo/python-ideas" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://mail.python.org/mailman/listinfo/python-ideas</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Code of Conduct:<span class="Apple-converted-space"> </span></span><a href="http://python.org/psf/codeofconduct/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://python.org/psf/codeofconduct/</a></div></blockquote></div><br class=""></body></html>