<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 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 <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><br class=""></div><div>I had thought that the solution would be in the .py implementation of the import</div><div>machinery not in the core C code.</div><div><br class=""></div><div>I was going to simply keep track of the names of the modules that are being imported</div><div>and raise an exception if an import attempted to import a module that had not completed</div><div>being imported. It seems from a quick loom at the code that this would be practical.</div><div><br class=""></div><div>Are you saying that there is a subtle point about import and detection of cycles that</div><div>means the work must be done in C?</div><div><br class=""></div><div>Barry</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><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="">-- <br class="">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" class="">ncoghlan@gmail.com</a>   |   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="">https://mail.python.org/mailman/listinfo/python-ideas<br class="">Code of Conduct: http://python.org/psf/codeofconduct/<br class=""><br class=""></div></div></blockquote></div><br class=""></body></html>