Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cycle not detected #23

@Jofkos

Description

@Jofkos

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions