[Python-ideas] ImportError raised for a circular import
barry at barrys-emacs.org
Tue Jun 13 16:35:28 EDT 2017
> On 13 Jun 2017, at 20:13, Antoine Rozo <antoine.rozo at gmail.com> wrote:
> But circular imports are sometimes needed in modules.
> For example when you have two classes in two different modules that reference each other in their methods (and because you can't pre-declare classes like in C++).
Really? It has always been a strong sign of a design bug in all the cases I have ever seen.
The example you suggest always fails when I accidentally write it.
Pylint will certainly shout loud that this case is an error.
> 2017-06-13 20:30 GMT+02:00 Barry Scott <barry at barrys-emacs.org>:
>> Recently I fell into the trap of creating a circular import and yet again it took time to figure out what was wrong.
>> I'm wondering why the python import code does not detect this error and raise an exception.
>> I took a look at the code and got as far as figuring out that I would need to add the detection to the
>> python 3 import code. Unless I missed something I cannot get the detection without
>> modifying the core code as I could see no way to hook the process cleanly.
>> Is it reasonable idea to add this detection to python?
>> I am willing to work on a patch.
>> Python-ideas mailing list
>> Python-ideas at python.org
>> Code of Conduct: http://python.org/psf/codeofconduct/
> Antoine Rozo
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas