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 #23

Open
Jofkos opened this issue Nov 1, 2022 · 0 comments
Open

cycle not detected #23

Jofkos opened this issue Nov 1, 2022 · 0 comments

Comments

@Jofkos
Copy link

Jofkos commented Nov 1, 2022

A rather primitive module cycle is not detected. Minimal working example:

reproduction
├── __init__.py
├── moduleA
│   ├── __init__.py
│   └── a_class.py
└── moduleB
    ├── __init__.py
    └── b_class.py

reproduction > moduleA > __init__.py:

from .a_class import ClassA

reproduction > moduleA > a_class.py:

import reproduction.moduleB


class ClassA:
    pass

reproduction > moduleB > __init__.py:

from .b_class import ClassB

reproduction > moduleB > b_class.py:

from ..moduleA import ClassA


class ClassB:
    pass

When running pycycle:

> pycycle --here --verbose
Trying to parse file: /private/tmp/reproduction/reproduction/__init__.py
Trying to parse file: /private/tmp/reproduction/reproduction/moduleB/__init__.py
Trying to parse file: /private/tmp/reproduction/reproduction/moduleB/b_class.py
Trying to parse file: /private/tmp/reproduction/reproduction/moduleA/a_class.py
Trying to parse file: /private/tmp/reproduction/reproduction/moduleA/__init__.py
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.

when trying to import moduleA:

> python3 -c 'import reproduction.moduleA'   
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/reproduction/reproduction/moduleA/__init__.py", line 1, in <module>
    from .a_class import ClassA
  File "/private/tmp/reproduction/reproduction/moduleA/a_class.py", line 1, in <module>
    import reproduction.moduleB
  File "/private/tmp/reproduction/reproduction/moduleB/__init__.py", line 1, in <module>
    from .b_class import ClassB
  File "/private/tmp/reproduction/reproduction/moduleB/b_class.py", line 1, in <module>
    from ..moduleA import ClassA
ImportError: cannot import name 'ClassA' from partially initialized module 'reproduction.moduleA' (most likely due to a circular import) (/private/tmp/reproduction/reproduction/moduleA/__init__.py)
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