summaryrefslogtreecommitdiffstats
path: root/Lib/json
diff options
context:
space:
mode:
authorMatthias Bussonnier <bussonniermatthias@gmail.com>2019-04-09 07:17:25 (GMT)
committerInada Naoki <songofacandy@gmail.com>2019-04-09 07:17:25 (GMT)
commita8abe097c1165db25b429ca02a65c4f8acbc062b (patch)
treed34fbcd712d64413f1754eadbaca13acd21a57e1 /Lib/json
parent5909ad1217aad200c69ffa794fcab285bacb609e (diff)
downloadcpython-a8abe097c1165db25b429ca02a65c4f8acbc062b.zip
cpython-a8abe097c1165db25b429ca02a65c4f8acbc062b.tar.gz
cpython-a8abe097c1165db25b429ca02a65c4f8acbc062b.tar.bz2
bpo-33461: emit DeprecationWarning when json.loads(encoding=...) is used (GH-6762)
Diffstat (limited to 'Lib/json')
-rw-r--r--Lib/json/__init__.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py
index 3bb4490..1ba8b48 100644
--- a/Lib/json/__init__.py
+++ b/Lib/json/__init__.py
@@ -296,7 +296,7 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
-def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
+def loads(s, *, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
"""Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance
containing a JSON document) to a Python object.
@@ -330,7 +330,7 @@ def loads(s, *, encoding=None, 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.
+ The ``encoding`` argument is ignored and deprecated since Python 3.1.
"""
if isinstance(s, str):
if s.startswith('\ufeff'):
@@ -342,6 +342,15 @@ def loads(s, *, encoding=None, 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):