You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New REPL does not include globals from executed module when used with -i #120678
If I have a module called foo.py with the following contents in the root of my CPython local clone:
classFoo: pass
Then running PYTHON_BASIC_REPL=1 ./python.exe -i foo.py, I get the following behaviour: foo.py is executed, and the Foo class is available in the globals of the REPL:
But with the new REPL, the Foo class isn't available!
~/dev/cpython (main)⚡ % ./python.exe -i foo.py
>>> Foo
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
Foo
NameError: name 'Foo' is not defined
>>>
This can be addressed in "Lib/_pyrepl/__main__.py". All imports and assignments in that module (e.g. CAN_USE_PYREPL, interactive_console, os, and sys) should be uniquely prefixed to avoid collisions and to allow clearing them before calling run_interactive(mainmodule).
Activity
eryksun commentedon Jun 18, 2024
It seems the new REPL doesn't get executed in the
__main__namespace. This can be worked around manually:>>> Foo Traceback (most recent call last): File "<python-input-0>", line 1, in <module> Foo NameError: name 'Foo' is not definedThis can be addressed in "Lib/_pyrepl/__main__.py". All imports and assignments in that module (e.g.
CAN_USE_PYREPL,interactive_console,os, andsys) should be uniquely prefixed to avoid collisions and to allow clearing them before callingrun_interactive(mainmodule).vstinner commentedon Jun 20, 2024
I marked #120798 as a duplicate of this issue.
AlexWaygood commentedon Jun 22, 2024
This is a regression that was caused by #119547.
pythongh-120678: pyrepl: Include globals from modules passed with `-i`
pythongh-120678: pyrepl: Include globals from modules passed with `-i`
gh-120678: pyrepl: Include globals from modules passed with `-i` (GH-…
pythongh-120678: pyrepl: Include globals from modules passed with `-i` (
[3.13] gh-120678: pyrepl: Include globals from modules passed with `-…
pythongh-120678: Guard against stdin.fileno() being unavailable
gh-120678: Guard against stdin.fileno() being unavailable (#121924)
pythongh-120678: Guard against stdin.fileno() being unavailable (pyth…
[3.13] gh-120678: Guard against stdin.fileno() being unavailable (GH-…
ambv commentedon Jul 22, 2024
This is solved now, thanks everyone!