> On 14 Jun 2017, at 07:33, Nick Coghlan <[email protected]> wrote: > > On 14 June 2017 at 13:02, Mahmoud Hashemi <[email protected]> wrote: >> That would be amazing! If there's anything I can do to help make that >> happen, please let me know. It'll almost certainly save that much time for >> me alone down the line, anyway :) > > The `IMPORT_FROM` opcode's error handling would probably be the best > place to start poking around: > https://github.com/python/cpython/blob/master/Python/ceval.c#L5055 > > If you can prove the concept there, that would: > > 1. Directly handle the "from x import y" and "import x.y as name" cases > 2. Provide a starting point for factoring out a "report missing module > attribute" helper that could be shared with ModuleType > > As an example of querying _frozen_importlib state from C code, I'd > point to https://github.com/python/cpython/blob/master/Python/import.c#L478 > <https://github.com/python/cpython/blob/master/Python/import.c#L478>
I had thought that the solution would be in the .py implementation of the import machinery not in the core C code. I was going to simply keep track of the names of the modules that are being imported and raise an exception if an import attempted to import a module that had not completed being imported. It seems from a quick loom at the code that this would be practical. Are you saying that there is a subtle point about import and detection of cycles that means the work must be done in C? Barry > > Cheers, > Nick. > > P.S. I also double checked that ImportError & AttributeError have > compatible binary layouts, so dual inheritance from them works :) > > -- > Nick Coghlan | [email protected] | Brisbane, Australia > _______________________________________________ > Python-ideas mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
