diff options
author | Julien Palard <julien@palard.fr> | 2021-04-13 16:03:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 16:03:22 (GMT) |
commit | fd79af7ae2574aaaa829e40ed780e17ef1f9be84 (patch) | |
tree | a85efb269287fd99d8e44a9213ad0dad4aaff73f /Doc | |
parent | eb77133564d74eb09ed63872a69b9827d4841b49 (diff) | |
download | cpython-fd79af7ae2574aaaa829e40ed780e17ef1f9be84.zip cpython-fd79af7ae2574aaaa829e40ed780e17ef1f9be84.tar.gz cpython-fd79af7ae2574aaaa829e40ed780e17ef1f9be84.tar.bz2 |
Doc: Try to enhance wording on circular imports. (GH-24705)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/faq/programming.rst | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 514ca04..ff78ca7 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1898,26 +1898,26 @@ How can I have modules that mutually import each other? Suppose you have the following modules: -foo.py:: +:file:`foo.py`:: from bar import bar_var foo_var = 1 -bar.py:: +:file:`bar.py`:: from foo import foo_var bar_var = 2 The problem is that the interpreter will perform the following steps: -* main imports foo -* Empty globals for foo are created -* foo is compiled and starts executing -* foo imports bar -* Empty globals for bar are created -* bar is compiled and starts executing -* bar imports foo (which is a no-op since there already is a module named foo) -* bar.foo_var = foo.foo_var +* main imports ``foo`` +* Empty globals for ``foo`` are created +* ``foo`` is compiled and starts executing +* ``foo`` imports ``bar`` +* Empty globals for ``bar`` are created +* ``bar`` is compiled and starts executing +* ``bar`` imports ``foo`` (which is a no-op since there already is a module named ``foo``) +* The import mechanism tries to read ``foo_var`` from ``foo`` globals, to set ``bar.foo_var = foo.foo_var`` The last step fails, because Python isn't done with interpreting ``foo`` yet and the global symbol dictionary for ``foo`` is still empty. |