detecting circular imports

Posted by wallacoloo on Stack Overflow See other posts from Stack Overflow or by wallacoloo
Published on 2010-03-09T01:11:14Z Indexed on 2010/03/09 1:21 UTC
Read the original article Hit count: 371

Filed under:
|

I'm working with a project that contains about 30 unique modules. It wasn't designed too well, so it's common that I create circular imports when adding some new functionality to the project.

Of course, when I add the circular import, I'm unaware of it. Sometimes it's pretty obvious I've made a circular import when I get an error like AttributeError: 'module' object has no attribute 'attribute' where I clearly defined 'attribute'. But other times, the code doesn't throw exceptions because of the way it's used.

So, to my question:

Is it possible to programmatically detect when and where a circular import is occuring?

© Stack Overflow or respective owner

Related posts about python

Related posts about circular-dependency