Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle not detected with empty __init__.py #25

Open
shobsi opened this issue Nov 7, 2024 · 0 comments
Open

Cycle not detected with empty __init__.py #25

shobsi opened this issue Nov 7, 2024 · 0 comments

Comments

@shobsi
Copy link

shobsi commented Nov 7, 2024

Have a circular import

(venv) $ tree .
.
├── alpha.py
└── beta.py

1 directory, 2 files

(venv)  $ cat alpha.py
from beta import Class2
class Class1:
    obj = Class2()

(venv)  $ cat beta.py
from alpha import Class1
class Class2:
    obj = Class1()

Python fails with the ImportError as expected:

(venv)  $ python alpha.py
Traceback (most recent call last):
  File "/cur/dir/alpha.py", line 1, in <module>
    from beta import Class2
  File "/cur/dir/beta.py", line 1, in <module>
    from alpha import Class1
  File "/cur/dir/alpha.py", line 1, in <module>
    from beta import Class2
ImportError: cannot import name 'Class2' from partially initialized module 'beta' (most likely due to a circular import) (/cur/dir/beta.py)

pycycle detects the cycle as expected:

(venv) $ pycycle --here
Project successfully transformed to AST, checking imports for cycles..
Cycle Found :(
alpha -> beta: Line 1 =>> alpha
Finished.

Create an empty __init__.py in the directory. After that pycycle can no longer detect the cycle.

(venv) $ touch __init__.py
(venv) $ pycycle --here
Project successfully transformed to AST, checking imports for cycles..
No worries, no cycles here!
If you think some cycle was missed, please open an Issue on Github.
Finished. 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant