Skip to content

Commit

Permalink
pythongh-76637: Deprecate the "undefined" codec
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jan 8, 2024
1 parent 931d7e0 commit 3984cc6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------
Expand Down Expand Up @@ -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
------------------------------

Expand Down
5 changes: 5 additions & 0 deletions Lib/encodings/undefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"""
import codecs
import warnings


warnings._deprecated('codec "undefined"', remove=(3, 15))


### Codec APIs

Expand Down
8 changes: 7 additions & 1 deletion Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate the ``undefined`` codec. Patch by Victor Stinner.

0 comments on commit 3984cc6

Please sign in to comment.