[Python-checkins] bpo-39377: json: Remove the encoding option. (GH-18075)

Inada Naoki webhook-mailer at python.org
Sun Jan 19 23:54:09 EST 2020


https://github.com/python/cpython/commit/5492bfcefec67b016e8239c0e9135bc2f03e3058
commit: 5492bfcefec67b016e8239c0e9135bc2f03e3058
branch: master
author: Inada Naoki <songofacandy at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-01-20T13:54:00+09:00
summary:

bpo-39377: json: Remove the encoding option. (GH-18075)

files:
A Misc/NEWS.d/next/Library/2020-01-20-13-00-35.bpo-39377.QSFdaU.rst
M Lib/json/__init__.py
M Lib/test/test_json/test_decode.py

diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py
index 1ba8b48bd78cd..2c52bdeba6754 100644
--- a/Lib/json/__init__.py
+++ b/Lib/json/__init__.py
@@ -329,8 +329,6 @@ def loads(s, *, cls=None, object_hook=None, parse_float=None,
 
     To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
     kwarg; otherwise ``JSONDecoder`` is used.
-
-    The ``encoding`` argument is ignored and deprecated since Python 3.1.
     """
     if isinstance(s, str):
         if s.startswith('\ufeff'):
@@ -342,15 +340,6 @@ def loads(s, *, cls=None, object_hook=None, parse_float=None,
                             f'not {s.__class__.__name__}')
         s = s.decode(detect_encoding(s), 'surrogatepass')
 
-    if "encoding" in kw:
-        import warnings
-        warnings.warn(
-            "'encoding' is ignored and deprecated. It will be removed in Python 3.9",
-            DeprecationWarning,
-            stacklevel=2
-        )
-        del kw['encoding']
-
     if (cls is None and object_hook is None and
             parse_int is None and parse_float is None and
             parse_constant is None and object_pairs_hook is None and not kw):
diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py
index 895c95b54c3b6..fdb9e62124ece 100644
--- a/Lib/test/test_json/test_decode.py
+++ b/Lib/test/test_json/test_decode.py
@@ -95,9 +95,5 @@ def test_negative_index(self):
         d = self.json.JSONDecoder()
         self.assertRaises(ValueError, d.raw_decode, 'a'*42, -50000)
 
-    def test_deprecated_encode(self):
-        with self.assertWarns(DeprecationWarning):
-            self.loads('{}', encoding='fake')
-
 class TestPyDecode(TestDecode, PyTest): pass
 class TestCDecode(TestDecode, CTest): pass
diff --git a/Misc/NEWS.d/next/Library/2020-01-20-13-00-35.bpo-39377.QSFdaU.rst b/Misc/NEWS.d/next/Library/2020-01-20-13-00-35.bpo-39377.QSFdaU.rst
new file mode 100644
index 0000000000000..8493ac88e4b72
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-01-20-13-00-35.bpo-39377.QSFdaU.rst
@@ -0,0 +1,2 @@
+Removed ``encoding`` option from :func:`json.loads`.  It has been deprecated
+since Python 3.1.



More information about the Python-checkins mailing list