REPL exits with traceback when str(sys.ps1) raises
Đang mở
Chưa có ai nhận issue này.
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:
Subject says it all. This is on the latest HEAD of main.
~/cpython$ g pull
Already up to date.
~/cpython$ make
Checked 112 modules (34 built-in, 78 shared, 0 n/a on macosx-14.6-x86_64, 0 disabled, 0 missing, 0 failed on import)
./python.exe -E ./Tools/build/generate-build-details.py `cat pybuilddir.txt`/build-details.json
~/cpython$ ./python.exe
Python 3.14.0a5+ (heads/main:ab11c097052, Feb 28 2025, 08:56:47) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> class C:
... def __str__(self): 1/0
...
>>> sys.ps1 = C()
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/guido/cpython/Lib/_pyrepl/__main__.py", line 6, in <module>
__pyrepl_interactive_console()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/guido/cpython/Lib/_pyrepl/main.py", line 59, in interactive_console
run_multiline_interactive_console(console)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/Users/guido/cpython/Lib/_pyrepl/simple_interact.py", line 143, in run_multiline_interactive_console
statement = multiline_input(more_lines, ps1, ps2)
File "/Users/guido/cpython/Lib/_pyrepl/readline.py", line 389, in multiline_input
return reader.readline()
~~~~~~~~~~~~~~~^^
File "/Users/guido/cpython/Lib/_pyrepl/reader.py", line 796, in readline
self.prepare()
~~~~~~~~~~~~^^
File "/Users/guido/cpython/Lib/_pyrepl/historical_reader.py", line 306, in prepare
super().prepare()
~~~~~~~~~~~~~~~^^
File "/Users/guido/cpython/Lib/_pyrepl/reader.py", line 643, in prepare
self.calc_screen()
~~~~~~~~~~~~~~~~^^
File "/Users/guido/cpython/Lib/_pyrepl/completing_reader.py", line 261, in calc_screen
screen = super().calc_screen()
File "/Users/guido/cpython/Lib/_pyrepl/reader.py", line 371, in calc_screen
prompt = self.get_prompt(ln, ll >= pos >= 0)
File "/Users/guido/cpython/Lib/_pyrepl/historical_reader.py", line 326, in get_prompt
return super().get_prompt(lineno, cursor_on_line)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/guido/cpython/Lib/_pyrepl/reader.py", line 552, in get_prompt
prompt = f"{ANSIColors.BOLD_MAGENTA}{prompt}{ANSIColors.RESET}"
^^^^^^^^
File "<python-input-1>", line 2, in __str__
def __str__(self): 1/0
~^~
ZeroDivisionError: division by zero
~/cpython$
Probably @pablogsal should look into this.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-131110
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện lỗi bằng lệnh tương tác được hiển thị trong báo cáo, sau đó bắt đầu tại Lib/_pyrepl/reader.py và lần theo get_prompt qua các tệp _pyrepl liên quan được nêu trong traceback. Kiểm tra PR gh-131110 được liên kết trước khi bắt đầu; hoàn tất khi một ngoại lệ từ str(sys.ps1) không còn khiến REPL thoát với traceback.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- cli
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100