diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 59b9281e6d2b89..e0490027c1e763 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -568,6 +568,12 @@ Deprecated * Deprecate undocumented :func:`!pydoc.ispackage` function. (Contributed by Zackery Spytz in :gh:`64020`.) +* Deprecate the ``undefined`` codec. This codec always raises a + :exc:`ValueError` exception when being used. It was intended for use by the + :mod:`site` module to switch off automatic string to Unicode coercion, but + it's no longer used by the :mod:`site` module. + (Contributed by Victor Stinner in :gh:`76637`.) + Pending Removal in Python 3.14 ------------------------------ @@ -721,6 +727,12 @@ Pending Removal in Python 3.15 All arguments will be removed from :func:`threading.RLock` in Python 3.15. (Contributed by Nikita Sobolev in :gh:`102029`.) +* The codec ``undefined`` is deprecated. This codec always raises a + :exc:`ValueError` exception when being used. It was intended for use by the + :mod:`site` module to switch off automatic string to Unicode coercion, but + it's no longer used by the :mod:`site` module. + (Contributed by Victor Stinner in :gh:`76637`.) + Pending Removal in Python 3.16 ------------------------------ diff --git a/Lib/encodings/undefined.py b/Lib/encodings/undefined.py index 4690288355c710..f40675fbeb82e6 100644 --- a/Lib/encodings/undefined.py +++ b/Lib/encodings/undefined.py @@ -10,6 +10,11 @@ """ import codecs +import warnings + + +warnings._deprecated('codec "undefined"', remove=(3, 15)) + ### Codec APIs diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index ff511a625a0194..e4b0421a51d329 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1,12 +1,13 @@ import codecs import contextlib import copy +import encodings import io import locale import pickle import sys import unittest -import encodings +import warnings from unittest import mock from test import support @@ -1744,6 +1745,11 @@ def test_open(self): self.assertIsInstance(file, codecs.StreamReaderWriter) def test_undefined(self): + # ignore the DeprecationWarning + with warnings.catch_warnings(): + warnings.simplefilter('ignore', category=DeprecationWarning) + codecs.lookup('undefined') + self.assertRaises(UnicodeError, codecs.encode, 'abc', 'undefined') self.assertRaises(UnicodeError, codecs.decode, b'abc', 'undefined') self.assertRaises(UnicodeError, codecs.encode, '', 'undefined') diff --git a/Misc/NEWS.d/next/Library/2024-01-08-23-55-50.gh-issue-76637.U9fXWx.rst b/Misc/NEWS.d/next/Library/2024-01-08-23-55-50.gh-issue-76637.U9fXWx.rst new file mode 100644 index 00000000000000..1e55b96d659e18 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-01-08-23-55-50.gh-issue-76637.U9fXWx.rst @@ -0,0 +1 @@ +Deprecate the ``undefined`` codec. Patch by Victor Stinner.