cyclic-import / R0401#
Cyclic import (%s)
Used when a cyclic import between two or more modules is detected.
def count_to_one(): return 1 def count_to_three(): from .bad2 import count_to_two return count_to_two() + 1
from .bad import count_to_one # [cyclic-import] def count_to_two(): return count_to_one() + 1
def count_to_one(): return 1 def count_to_two(): return count_to_one() + 1 def count_to_three(): return count_to_two() + 1
The good code is just an example. There are various strategies to resolving cyclic imports and the best choice relies heavily on the context of the code and the affected modules.
Created by the imports checker.