Skip to content

gh-145834: email.charset: remove viscii from CHARSETS — no Python codec exists#145835

Closed
stefanzetzsche wants to merge 4 commits intopython:mainfrom
stefanzetzsche:fix/email_charset
Closed

gh-145834: email.charset: remove viscii from CHARSETS — no Python codec exists#145835
stefanzetzsche wants to merge 4 commits intopython:mainfrom
stefanzetzsche:fix/email_charset

Conversation

@stefanzetzsche
Copy link
Contributor

@stefanzetzsche stefanzetzsche commented Mar 11, 2026

Problem

email.charset registers viscii in its CHARSETS table with QP header and body encoding, but Python ships no viscii codec. Any encoding operation on Charset('viscii') raises LookupError: unknown encoding: viscii.

Reproducer

from email.charset import Charset
Charset('viscii').header_encode('')  # LookupError: unknown encoding: viscii

Fix

Remove the viscii entry from CHARSETS in Lib/email/charset.py. There is no Python codec for viscii and no obvious mapping to add via CODEC_MAP.

Tests

Two test cases added to TestCharset in Lib/test/test_email/test_email.py:

  • test_viscii_not_registered — verifies viscii is no longer in CHARSETS.
  • test_all_charsets_have_codecs — verifies every charset registered in CHARSETS maps to a resolvable Python codec, preventing this class of bug from recurring.

email.charset registered viscii but Python has no viscii codec, causing
LookupError on any encoding operation.

Removed viscii from CHARSETS table.

sim: https://taskei.amazon.dev/tasks/TODO
@stefanzetzsche stefanzetzsche marked this pull request as ready for review March 11, 2026 15:59
@stefanzetzsche stefanzetzsche requested a review from a team as a code owner March 11, 2026 16:00
@picnixz
Copy link
Member

picnixz commented Mar 11, 2026

Please, avoid opening PRs without the issue having been triaged. We welcome contributions, but we don't want PRs sitting there because they were generated in series (I assume that you are using an LLM to generate the description and I also think that it helped you for the writing the code; please read https://devguide.python.org/getting-started/generative-ai/ as well).

@picnixz picnixz closed this Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants