tokenize.detect_encoding has issues with \r
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
The issue names tokenize.detect_encoding and provides a complete carriage-return reproduction. Start by running the supplied script, then locate the encoding-detection implementation and existing tests; done means the coding header is detected as big5 when \r precedes it, with regression coverage for this input.
Written by the indexing model from the issue text.
Description
Tokenize does not correctly detect encodings when the carriage return character is involved. In this program, it does not detect the header, since it does not consider the \r to start a new line.
import tokenize
import runpy
code = """\r# coding: big5
print('錯誤的答案')
"""
with open('file.py', 'w', encoding='big5') as file:
file.write(code)
with open('file.py', 'rb') as file:
print(tokenize.detect_encoding(file.readline))
# result: ('utf-8', [b'\r# coding: big5\r\n', b'\r\n'])
runpy.run_path('file.py')
# prints 錯誤的答案 as required
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 558
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/cpython
-
docs pending
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
stdlib type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
build type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
stdlib topic-email type-feature
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100