[Python-ideas] ImportError raised for a circular import

Nick Coghlan ncoghlan at gmail.com
Wed Jun 14 02:33:27 EDT 2017


On 14 June 2017 at 13:02, Mahmoud Hashemi <mahmoud at hatnote.com> 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

Cheers,
Nick.

P.S. I also double checked that ImportError & AttributeError have
compatible binary layouts, so dual inheritance from them works :)

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list