Closed
Description
Bug report
Bug description:
Description
When starting the Python 3.13.0 REPL in a directory containing a file named code.py
, the REPL attempts to load this local file instead of the standard library code
module. This causes conflicts and errors when initializing the interactive environment. This is also a major security issue.
Steps to Reproduce
- Create a directory and navigate to it
- Create a file named
code.py
in 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 library code
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 local code.py
file instead of the standard library module:
aleksa@aleksa:~/testing13$ python
Python 3.13.0 (main, Oct 8 2024, 16:45:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "<frozen site>", line 498, in register_readline
File "/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/readline.py", line 39, in <module>
from . import commands, historical_reader
File "/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/historical_reader.py", line 26, in <module>
from .reader import Reader
File "/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/reader.py", line 32, in <module>
from . import commands, console, input
File "/home/aleksa/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/console.py", line 153, in <module>
class InteractiveColoredConsole(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 library code
module, regardless of local files in the current directory.
CPython versions tested on:
3.13
Operating systems tested on:
Linux