Repository navigation
New REPL does not include globals from executed module when used with -i #120678
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-replRelated to the interactive shellRelated to the interactive shell
on Jun 18, 2024 It seems the new REPL doesn't get executed in the
__main__namespace. This can be worked around manually:$ python -ic "class Foo: pass">>> Foo Traceback (most recent call last): File "<python-input-0>", line 1, in <module> Foo NameError: name 'Foo' is not defined>>> import sys >>> from _pyrepl.simple_interact import run_multiline_interactive_console >>> run_multiline_interactive_console(sys.modules['__main__']) >>> Foo <class '__main__.Foo'> >>> dir() ['CAN_USE_PYREPL', 'Foo', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'interactive_console', 'os', 'sys']
This 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).I marked #120798 as a duplicate of this issue.
This is a regression that was caused by #119547.
- added a commit that references this issue
on Jul 17, 2024 - added a commit that references this issue
on Jul 17, 2024 This is solved now, thanks everyone!
Reacted by Alex Waygood
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
If I have a module called
foo.py with the following contents in the root of my CPython local clone:Then running
PYTHON_BASIC_REPL=1 ./python.exe -i foo.py, I get the following behaviour:foo.pyis executed, and theFooclass is available in the globals of the REPL:But with the new REPL, the
Fooclass 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 >>>CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
-i#120904-i(GH-120904) #121916