guilatrova / tryceratops

A linter to prevent exception handling antipatterns in Python (limited only for those who like dinosaurs).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Circular import detected

MaxG87 opened this issue · comments

I wanted to write a test whether arbitrary invalid code can be handled correctly. The test can be found below; I had it in src/tests/fuzzing_test.py. EDIT: I reduced the "test" to the bare minimum necessary to reproduce the problem.

When I try to execute this test using poetry run pytest src/tests/fuzzing_test.py I get an error message that complains about possible circular imports. I have no idea how that is possible and thus wanted to escalate this to the maintainer. The error message can be found below the source code.

from tryceratops.files.discovery import FileDiscovery
============================= test session starts ==============================
platform linux -- Python 3.9.2, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/user/workspace/tryceratops
plugins: cov-2.12.1, hypothesis-6.14.3
collected 0 items / 1 error

==================================== ERRORS ====================================
__________________ ERROR collecting src/tests/fuzzing_test.py __________________
ImportError while importing test module '/home/user/workspace/tryceratops/src/tests/fuzzing_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
src/tests/fuzzing_test.py:7: in <module>
    from tryceratops.files.discovery import FileDiscovery
src/tryceratops/files/__init__.py:1: in <module>
    from .discovery import FileDiscovery, load_config
src/tryceratops/files/discovery.py:9: in <module>
    from tryceratops.types import ParsedFileType, PyprojectConfig
src/tryceratops/types.py:4: in <module>
    from tryceratops.filters import FileFilter
src/tryceratops/filters.py:6: in <module>
    from tryceratops.analyzers import BaseAnalyzer
src/tryceratops/analyzers/__init__.py:4: in <module>
    from .main import Runner
src/tryceratops/analyzers/main.py:5: in <module>
    from tryceratops.filters import GlobalFilter
E   ImportError: cannot import name 'GlobalFilter' from partially initialized module 'tryceratops.filters' (most likely due to a circular import) (/home/user/workspace/tryceratops/src/tryceratops/filters.py)
=========================== short test summary info ============================
ERROR src/tests/fuzzing_test.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.08s ===============================

I created the following and it worked:

from tryceratops.files.discovery import FileDiscovery


def test_a():
    FileDiscovery()

image

If you are still having problems, please, create a PR or a branch so I can help you debug it.