Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Fallback to utf-8 or iso-8859-1 if decoding using chardet-detected encoding fails

オープン
#3,985 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@ekanshul がすでに取り組んでいます。

2026年9月20日 から。

  • #4030 @ekanshul による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
tooling

調査の方向性

Start in codespell_lib/_codespell.py, especially open_with_chardet and get_lines, which appear in the traceback. Check the existing tests for hard encoding detection and run the relevant tests. Done means a decoding failure with the detected encoding falls back to utf-8 or iso-8859-1 instead of crashing; an open pull request is already linked.

索引モデルが issue の本文から書いたものです。

説明

Consider file gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb from the binutils-gdb repo.

This works without problems:

$ codespell gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
$ 

which means utf-8 decoding is used.

However, with --hard-encoding-detection we get:

$ codespell --hard-encoding-detection gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
Traceback (most recent call last):
  File "/home/vries/codespell/python-3.9-venv/bin/codespell", line 6, in <module>
    sys.exit(_script_main())
  File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 1294, in _script_main
    return main(*sys.argv[1:])
  File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 1534, in main
    bad_count += parse_file(
  File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 1217, in parse_file
    fragments, encoding = file_opener.open(filename)
  File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 250, in open
    return self.open_with_chardet(filename)
  File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 277, in open_with_chardet
    lines = self.get_lines(f)
  File "/home/vries/codespell/codespell.git/codespell_lib/_codespell.py", line 328, in get_lines
    fragments.append((False, line_number, f.readlines()))
  File "/usr/lib64/python3.9/encodings/cp1254.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 943: character maps to <undefined>

What happens is that chardet detects CP1254 (aka Windows-1254) encoding, but decoding using that encoding fails.

When not using --hard-encoding-detection, we first try utf-8, and if that doesn't work, warn and try iso-8859-1.

It seems logical to extend the fallback handling to --hard-encoding-detection:

$ codespell --hard-encoding-detection gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
WARNING: Cannot decode file using encoding "Windows-1254": gdb/testsuite/gdb.ada/non-ascii-utf-8/pack.adb
WARNING: Trying next encoding "utf-8"
$
主要言語
Python
スター
2.4k
フォーク
531
平均マージ
15時間 5分
マージ済み PR(30日)
18

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

codespell-project/codespell のほかの issue

codespell-project/codespell の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。