-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Description
Bug report
Bug description:
After upgrade from Python 3.12, code in a top-level file can no longer access variables (like modules, etc.) when the execution begins the interactive session.
In the simplest example, suppose I have a file, code.py that contains the following:
import osNow, if I run Python with this module interactively (python -i code.py), I can't access the os module in the Interactive (REPL) session:
>>> os.listdir('.')
NameError: name 'os' is not defined. Did you forget to import 'os'?But, to illustrate why this is a problem, consider if code.py had the following contents:
import os
from threading import Thread
def __nstest():
import time
time.sleep(5)
print(os.listdir('.'))
if __name__ == '__main__':
Thread(target=__nstest).start()
print(os.listdir('.'))Again, still a contrived example, but if my __main__ module is passing a function for use later in execution, but that function can no longer access the modules that the __main__ module has imported, this leads to broken execution of code that formerly worked prior to Python 3.13 in Interactive mode. This sounds like it may relate to the new REPL and namespace issues that have arisen (gh-118908).
CPython versions tested on:
3.13.9
Operating systems tested on:
Linux