Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Bug report
Bug description:
Description
When starting the Python 3.13.0 REPL in a directory containing a file namedcode.py, the REPL attempts to load this local file instead of the standard librarycode module. This causes conflicts and errors when initializing the interactive environment. This is also amajor security issue.
Steps to Reproduce
- Create a directory and navigate to it
- Create a file named
code.pyin this directory - Ensure Python 3.13.0 is installed (e.g., using pyenv)
- Start the Python 3.13.0 REPL in this directory
Expected Behavior
The Python REPL should start normally, using the standard librarycode module for its interactive features.
Actual Behavior
The REPL fails to initialize properly, producing an error message indicating that it's attempting to use the localcode.py file instead of the standard library module:
aleksa@aleksa:~/testing13$ pythonPython 3.13.0 (main, Oct 8 2024, 16:45:05) [GCC 11.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.Failed calling sys.__interactivehook__Traceback (most recent call last): File"<frozen site>", line498, inregister_readline File"/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/readline.py", line39, in<module>from .import commands, historical_reader File"/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/historical_reader.py", line26, in<module>from .readerimport Reader File"/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/reader.py", line32, in<module>from .import commands, console,input File"/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/console.py", line153, in<module>classInteractiveColoredConsole(code.InteractiveConsole):^^^^^^^^^^^^^^^^^^^^^^^AttributeError:module 'code' has no attribute 'InteractiveConsole' (consider renaming '/home/aleksa/testing13/code.py' since it has the same name as the standard library module named 'code' and the import system gives it precedence)warning:can't use pyrepl: module 'code' has no attribute 'InteractiveConsole' (consider renaming '/home/aleksa/testing13/code.py' since it has the same name as the standard library module named 'code' and the import system gives it precedence)>>>
Additional Context
- This behavior is not observed in Python 3.12.7
- The issue seems to be related to how Python 3.13.0 handles module imports in the REPL initialization process
System Information
- OS: Linux (Ubuntu 22.04)
- Python version: 3.13.0
- Installation method: pyenv
Possible Solution
The REPL initialization process should be modified to ensure it uses the standard librarycode module, regardless of local files in the current directory.
CPython versions tested on:
3.13
Operating systems tested on:
Linux