tokenize.detect_encoding has issues with \r
オープン
まだ誰も着手していません。
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue では tokenize.detect_encoding が示され、キャリッジリターンを含む完全な再現手順が提供されています。まず提供されたスクリプトを実行し、次にエンコーディング検出の実装と既存のテストを見つけます。\r が先行する場合にコーディングヘッダーが big5 として検出され、この入力に対するリグレッションカバレッジがあれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100