File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -1898,26 +1898,26 @@ How can I have modules that mutually import each other?
1898
1898
1899
1899
Suppose you have the following modules:
1900
1900
1901
- foo.py::
1901
+ :file: ` foo.py ` ::
1902
1902
1903
1903
from bar import bar_var
1904
1904
foo_var = 1
1905
1905
1906
- bar.py::
1906
+ :file: ` bar.py ` ::
1907
1907
1908
1908
from foo import foo_var
1909
1909
bar_var = 2
1910
1910
1911
1911
The problem is that the interpreter will perform the following steps:
1912
1912
1913
- * main imports foo
1914
- * Empty globals for foo are created
1915
- * foo is compiled and starts executing
1916
- * foo imports bar
1917
- * Empty globals for bar are created
1918
- * bar is compiled and starts executing
1919
- * bar imports foo (which is a no-op since there already is a module named foo)
1920
- * bar.foo_var = foo.foo_var
1913
+ * main imports `` foo ``
1914
+ * Empty globals for `` foo `` are created
1915
+ * `` foo `` is compiled and starts executing
1916
+ * `` foo `` imports `` bar ``
1917
+ * Empty globals for `` bar `` are created
1918
+ * `` bar `` is compiled and starts executing
1919
+ * `` bar `` imports `` foo `` (which is a no-op since there already is a module named `` foo `` )
1920
+ * The import mechanism tries to read `` foo_var `` from `` foo `` globals, to set `` bar.foo_var = foo.foo_var ``
1921
1921
1922
1922
The last step fails, because Python isn't done with interpreting ``foo `` yet and
1923
1923
the global symbol dictionary for ``foo `` is still empty.
You can’t perform that action at this time.
0 commit comments