5

Circular imports in Python can lead to suddenly appearing bugs.

I guess it should be quite easy to detect them automatically:

  1. Import all code
  2. Build a graph
  3. Check for cycles.

Lazy imports which happen during run time are out of the scope of this question.

Does anybody know a tool which can detect circular imports in Python?

2

pylint does it. But it is not obvious for pylint newbees, since you need to call pytlint with both file names as argument.

See https://bitbucket.org/logilab/pylint/issue/515/recursive-import-not-detected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.