Skip to content

Commit 8fe826e

Browse files
DanielNoordPierre-Sassoulas
authored andcommitted
Add documentation for cyclic-import
Example of cyclic import where the cyclic import does not crash python
1 parent be15ae4 commit 8fe826e

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def count_to_one():
2+
return 1
3+
4+
5+
def count_to_three():
6+
from .bad2 import count_to_two # [cyclic-import]
7+
8+
return count_to_two() + 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .bad import count_to_one
2+
3+
4+
def count_to_two():
5+
return count_to_one() + 1
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
You can help us make the doc better `by contributing <https://github.com/pylint-dev/pylint/issues/5953>`_ !
1+
The good code is just an example. There are various strategies to resolving
2+
cyclic imports and the best choice relies heavily on the context of the code
3+
and the affected modules.
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
# This is a placeholder for correct code for this message.
1+
def count_to_one():
2+
return 1
3+
4+
5+
def count_to_two():
6+
return count_to_one() + 1
7+
8+
9+
def count_to_three():
10+
return count_to_two() + 1

0 commit comments

Comments
 (0)