diff --git a/Lib/email/charset.py b/Lib/email/charset.py index 5036c3f58a5633..c377809147ee76 100644 --- a/Lib/email/charset.py +++ b/Lib/email/charset.py @@ -50,7 +50,7 @@ 'iso-8859-15': (QP, QP, None), 'iso-8859-16': (QP, QP, None), 'windows-1252':(QP, QP, None), - 'viscii': (QP, QP, None), + # 'viscii' removed - no Python codec exists 'us-ascii': (None, None, None), 'big5': (BASE64, BASE64, None), 'gb2312': (BASE64, BASE64, None), diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 4e6c213510c74c..192d8aedec5c44 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -5008,6 +5008,29 @@ def test_unicode_charset_name(self): self.assertEqual(str(charset), 'us-ascii') self.assertRaises(errors.CharsetError, Charset, 'asc\xffii') + def test_viscii_not_registered(self): + # viscii has no Python codec, so it should not be in CHARSETS. + from email.charset import CHARSETS + self.assertNotIn('viscii', CHARSETS) + + def test_all_charsets_have_codecs(self): + # Every charset registered in CHARSETS should have a resolvable + # Python codec (via CODEC_MAP or by name). + import codecs + from email.charset import CHARSETS, CODEC_MAP + for name in CHARSETS: + codec_name = CODEC_MAP.get(name, name) + if codec_name is None: + continue + with self.subTest(charset=name, codec=codec_name): + try: + codecs.lookup(codec_name) + except LookupError: + self.fail( + f"charset {name!r} maps to codec {codec_name!r} " + f"which is not available" + ) + # Test multilingual MIME headers. diff --git a/Misc/NEWS.d/next/Library/2026-03-11-15-59-25.gh-issue-145834._UxpJY.rst b/Misc/NEWS.d/next/Library/2026-03-11-15-59-25.gh-issue-145834._UxpJY.rst new file mode 100644 index 00000000000000..ba42cfde64a31f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-11-15-59-25.gh-issue-145834._UxpJY.rst @@ -0,0 +1,3 @@ +Remove ``viscii`` from :mod:`email.charset` ``CHARSETS`` table. Python has +no ``viscii`` codec, so any encoding operation on ``Charset('viscii')`` +raised :exc:`LookupError`.