Skip to content

Commit

Permalink
Add documentation for cyclic-import
Browse files Browse the repository at this point in the history
Example of cyclic import where the cyclic import does not crash python
  • Loading branch information
DanielNoord authored and Pierre-Sassoulas committed Mar 3, 2023
1 parent 81bb644 commit 60374a0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions doc/data/messages/c/cyclic-import/bad/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def count_to_one():
return 1


def count_to_three():
from .bad2 import count_to_two # [cyclic-import]

return count_to_two() + 1
5 changes: 5 additions & 0 deletions doc/data/messages/c/cyclic-import/bad/bad2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .bad import count_to_one


def count_to_two():
return count_to_one() + 1
4 changes: 3 additions & 1 deletion doc/data/messages/c/cyclic-import/details.rst
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
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.
11 changes: 10 additions & 1 deletion doc/data/messages/c/cyclic-import/good.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# This is a placeholder for correct code for this message.
def count_to_one():
return 1


def count_to_two():
return count_to_one() + 1


def count_to_three():
return count_to_two() + 1

0 comments on commit 60374a0

Please sign in to comment.