Unicode characters ≥ 0x10000 cannot be inputted/behaves unusually at the REPL terminal.
Chưa có ai nhận issue này.
- 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:
When the machine locale is set to UTF-8, when inputting a Unicode character ≥ 0x10000:
In CPython 3.13.5:
https://github.com/user-attachments/assets/7777b063-76fe-4929-b854-cae7d61807d2
In Cpython 3.14.0b4:
>>> Traceback (most recent call last):
File "*\Python\Python314\Lib\_pyrepl\readline.py", line 394, in multiline_input
return reader.readline()
~~~~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 748, in readline
self.handle1()
~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 731, in handle1
self.do_cmd(cmd)
~~~~~~~~~~~^^^^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 661, in do_cmd
self.refresh()
~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 638, in refresh
self.screen = self.calc_screen()
~~~~~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\completing_reader.py", line 261, in calc_screen
screen = super().calc_screen()
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 315, in calc_screen
colors = list(gen_colors(self.get_unicode()))
File "*\Python\Python314\Lib\_pyrepl\utils.py", line 108, in gen_colors
for color in gen_colors_from_token_stream(gen, line_lengths):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "*\Python\Python314\Lib\_pyrepl\utils.py", line 168, in gen_colors_from_token_stream
for prev_token, token, next_token in token_window:
^^^^^^^^^^^^
File "*\Python\Python314\Lib\_pyrepl\utils.py", line 363, in prev_next_window
window = deque((None, next(iterator)), maxlen=3)
~~~~^^^^^^^^^^
File "*\Python\Python314\Lib\tokenize.py", line 582, in _generate_tokens_from_c_tokenizer
for info in it:
^^
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed
>>> Traceback (most recent call last):
File "*\Python\Python314\Lib\_pyrepl\readline.py", line 394, in multiline_input
return reader.readline()
~~~~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 748, in readline
self.handle1()
~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 731, in handle1
self.do_cmd(cmd)
~~~~~~~~~~~^^^^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 661, in do_cmd
self.refresh()
~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 638, in refresh
self.screen = self.calc_screen()
~~~~~~~~~~~~~~~~^^
File "*\Python\Python314\Lib\_pyrepl\completing_reader.py", line 261, in calc_screen
screen = super().calc_screen()
File "*\Python\Python314\Lib\_pyrepl\reader.py", line 315, in calc_screen
colors = list(gen_colors(self.get_unicode()))
File "*\Python\Python314\Lib\_pyrepl\utils.py", line 108, in gen_colors
for color in gen_colors_from_token_stream(gen, line_lengths):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "*\Python\Python314\Lib\_pyrepl\utils.py", line 168, in gen_colors_from_token_stream
for prev_token, token, next_token in token_window:
^^^^^^^^^^^^
File "*\Python\Python314\Lib\_pyrepl\utils.py", line 363, in prev_next_window
window = deque((None, next(iterator)), maxlen=3)
~~~~^^^^^^^^^^
File "*\Python\Python314\Lib\tokenize.py", line 582, in _generate_tokens_from_c_tokenizer
for info in it:
^^
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed
Two surrogates were "inputted" and so two UnicodeEncodeErrors.
CPython versions tested on:
3.13, 3.14
Operating systems tested on:
Windows
Linked PRs
- gh-136639
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
Bắt đầu với đường dẫn traceback qua Lib/_pyrepl/readline.py, reader.py, completing_reader.py, utils.py và Lib/tokenize.py, sau đó kiểm tra PR được liên kết gh-136639. Tái hiện sự cố trên Windows với locale UTF-8 và một ký tự ở U+10000 hoặc cao hơn; được xem là hoàn tất khi thao tác nhập vào REPL và refresh hoàn tất mà không có UnicodeEncodeError liên quan đến surrogate đã được báo cáo.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100