bndr / pycycle

Tool for pinpointing circular imports in Python. Find cyclic imports in any project
MIT License
337 stars 23 forks source link

Bug: Subpackage circular imports not detected #15

Open DomHudson opened 4 years ago

DomHudson commented 4 years ago

Summary

My example is the following package structure where package.subpackage.module imports from package.module and visa-versa.

.
├── package
│   ├── __init__.py
│   ├── module.py
│   └── subpackage
│       ├── __init__.py
│       └── module.py
└── run.py

run.py

from package.module import Anything

package/subpackage/module.py

from package.module import Anything

class Thing:
    pass

package/module.py

from package.subpackage.module import Thing

class Anything:
    pass

Expected behaviour

I consider this a circular import but pycycle detects no errors.

Executing run.py results in a circular import error:

Traceback (most recent call last):
  File "run.py", line 1, in <module>
    from package.module import Anything
  File "/home/dom/Code/package/package/module.py", line 1, in <module>
    from package.subpackage.module import Thing
  File "/home/dom/Code/package/package/subpackage/module.py", line 1, in <module>
    from package.module import Anything
ImportError: cannot import name 'Anything' from 'package.module' (/home/dom/Code/package/package/module.py)

An archive containing the package structure and code. package.tar.gz