bpo-33461: emit DeprecationWarning when json.loads(encoding=...) is u… · python/cpython@a8abe09 (original) (raw)
`@@ -296,7 +296,7 @@ def load(fp, *, cls=None, object_hook=None, parse_float=None,
`
296
296
`parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
`
297
297
``
298
298
``
299
``
`-
def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
`
``
299
`+
def loads(s, *, cls=None, object_hook=None, parse_float=None,
`
300
300
`parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
`
301
301
``` """Deserialize s
(a str
, bytes
or bytearray
instance
`302`
`302`
` 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,
`
`330`
`330`
``` To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
331
331
``` kwarg; otherwise JSONDecoder
is used.
`332`
`332`
``
`333`
``
``` -
The ``encoding`` argument is ignored and deprecated.
``
333
The ``encoding`` argument is ignored and deprecated since Python 3.1.
334
334
` """
`
335
335
`if isinstance(s, str):
`
336
336
`if s.startswith('\ufeff'):
`
`@@ -342,6 +342,15 @@ def loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None,
`
342
342
`f'not {s.class.name}')
`
343
343
`s = s.decode(detect_encoding(s), 'surrogatepass')
`
344
344
``
``
345
`+
if "encoding" in kw:
`
``
346
`+
import warnings
`
``
347
`+
warnings.warn(
`
``
348
`+
"'encoding' is ignored and deprecated. It will be removed in Python 3.9",
`
``
349
`+
DeprecationWarning,
`
``
350
`+
stacklevel=2
`
``
351
`+
)
`
``
352
`+
del kw['encoding']
`
``
353
+
345
354
`if (cls is None and object_hook is None and
`
346
355
`parse_int is None and parse_float is None and
`
347
356
`parse_constant is None and object_pairs_hook is None and not kw):
`