python / python/cpython

REPLs don't handle `SystemError` from the compiler

Đang mở
#150,732 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@johnslavik đang làm issue này rồi.

Từ ngày 1/6/2026.

3.14 3.15 3.16 stdlib topic-repl type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug report

Bug description:

During investigating #150700 I found that running the snippet class X: [(lambda: __class__)() for () in ()] causes the following bugs to appear:

  1. The REPL leaks _IncompleteInputError, which aborts writing the user input to history
  2. The user input isn't shown; Traceback is shown immediately after the prompt string >>>
❯ ./python.exe
Python 3.16.0a0 (heads/gh-143535-singledispatchmethod-dispatches-on-first-argument:fad06746051, M) [Clang 17.0.0 (clang-1700.6.3.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> Traceback (most recent call last):r () in ()]
  File "/Users/bartosz.slawecki/Python/cpython/Lib/codeop.py", line 64, in _maybe_compile
    compiler(source, filename, symbol, flags=flags)
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bartosz.slawecki/Python/cpython/Lib/codeop.py", line 117, in __call__
    codeob = compile(source, filename, symbol, flags, True)
  File "<stdin>", line 1
    class X: [(lambda: __class__)() for () in ()]
                                                ^
_IncompleteInputError: incomplete input

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/bartosz.slawecki/Python/cpython/Lib/_pyrepl/readline.py", line 406, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/Users/bartosz.slawecki/Python/cpython/Lib/_pyrepl/reader.py", line 1021, in readline
    self.handle1()
    ~~~~~~~~~~~~^^
  File "/Users/bartosz.slawecki/Python/cpython/Lib/_pyrepl/reader.py", line 1004, in handle1
    self.do_cmd(cmd)
    ~~~~~~~~~~~^^^^^
  File "/Users/bartosz.slawecki/Python/cpython/Lib/_pyrepl/reader.py", line 924, in do_cmd
    command.do()
    ~~~~~~~~~~^^
  File "/Users/bartosz.slawecki/Python/cpython/Lib/_pyrepl/readline.py", line 297, in do
    r.more_lines is not None and r.more_lines(text)
                                 ~~~~~~~~~~~~^^^^^^
  File "/Users/bartosz.slawecki/Python/cpython/Lib/_pyrepl/simple_interact.py", line 85, in _more_lines
    code = console.compile(src, "<stdin>", "single")
  File "/Users/bartosz.slawecki/Python/cpython/Lib/codeop.py", line 154, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol, flags=self.compiler.flags)
  File "/Users/bartosz.slawecki/Python/cpython/Lib/codeop.py", line 67, in _maybe_compile
    compiler(source + "\n", filename, symbol, flags=flags)
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bartosz.slawecki/Python/cpython/Lib/codeop.py", line 117, in __call__
    codeob = compile(source, filename, symbol, flags, True)
SystemError: compiler_lookup_arg(name='__class__') with reftype=5 failed in X; freevars of code <lambda>: ('__class__',)

I believe SystemError should be handled.

CPython versions tested on:

3.14, 3.15, 3.16, CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-151480

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.