Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python 3.13.0 REPL loads local files unexpectedly, causing conflicts and security issues #125140

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixestopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errortype-securityA security issue
@aleksa

Description

@aleksa

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

  1. Create a directory and navigate to it
  2. Create a file namedcode.py in this directory
  3. Ensure Python 3.13.0 is installed (e.g., using pyenv)
  4. 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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errortype-securityA security issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp