Kaydet (Commit) aacd53f6 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #18726: All optional parameters of the dump(), dumps(),

load() and loads() functions and JSONEncoder and JSONDecoder class
constructors in the json module are now keyword-only.
üst 43354375
...@@ -126,7 +126,7 @@ See :ref:`json-commandline` for detailed documentation. ...@@ -126,7 +126,7 @@ See :ref:`json-commandline` for detailed documentation.
Basic Usage Basic Usage
----------- -----------
.. function:: dump(obj, fp, skipkeys=False, ensure_ascii=True, \ .. function:: dump(obj, fp, *, skipkeys=False, ensure_ascii=True, \
check_circular=True, allow_nan=True, cls=None, \ check_circular=True, allow_nan=True, cls=None, \
indent=None, separators=None, default=None, \ indent=None, separators=None, default=None, \
sort_keys=False, **kw) sort_keys=False, **kw)
...@@ -184,8 +184,11 @@ Basic Usage ...@@ -184,8 +184,11 @@ Basic Usage
:meth:`default` method to serialize additional types), specify it with the :meth:`default` method to serialize additional types), specify it with the
*cls* kwarg; otherwise :class:`JSONEncoder` is used. *cls* kwarg; otherwise :class:`JSONEncoder` is used.
.. versionchanged:: 3.6
All optional parameters are now :ref:`keyword-only <keyword-only_parameter>`.
.. function:: dumps(obj, skipkeys=False, ensure_ascii=True, \
.. function:: dumps(obj, *, skipkeys=False, ensure_ascii=True, \
check_circular=True, allow_nan=True, cls=None, \ check_circular=True, allow_nan=True, cls=None, \
indent=None, separators=None, default=None, \ indent=None, separators=None, default=None, \
sort_keys=False, **kw) sort_keys=False, **kw)
...@@ -209,7 +212,7 @@ Basic Usage ...@@ -209,7 +212,7 @@ Basic Usage
the original one. That is, ``loads(dumps(x)) != x`` if x has non-string the original one. That is, ``loads(dumps(x)) != x`` if x has non-string
keys. keys.
.. function:: load(fp, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) .. function:: load(fp, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Deserialize *fp* (a ``.read()``-supporting :term:`file-like object` Deserialize *fp* (a ``.read()``-supporting :term:`file-like object`
containing a JSON document) to a Python object using this :ref:`conversion containing a JSON document) to a Python object using this :ref:`conversion
...@@ -257,7 +260,10 @@ Basic Usage ...@@ -257,7 +260,10 @@ Basic Usage
If the data being deserialized is not a valid JSON document, a If the data being deserialized is not a valid JSON document, a
:exc:`JSONDecodeError` will be raised. :exc:`JSONDecodeError` will be raised.
.. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) .. versionchanged:: 3.6
All optional parameters are now :ref:`keyword-only <keyword-only_parameter>`.
.. function:: loads(s, *, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Deserialize *s* (a :class:`str` instance containing a JSON document) to a Deserialize *s* (a :class:`str` instance containing a JSON document) to a
Python object using this :ref:`conversion table <json-to-py-table>`. Python object using this :ref:`conversion table <json-to-py-table>`.
...@@ -271,7 +277,7 @@ Basic Usage ...@@ -271,7 +277,7 @@ Basic Usage
Encoders and Decoders Encoders and Decoders
--------------------- ---------------------
.. class:: JSONDecoder(object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None) .. class:: JSONDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)
Simple JSON decoder. Simple JSON decoder.
...@@ -341,6 +347,9 @@ Encoders and Decoders ...@@ -341,6 +347,9 @@ Encoders and Decoders
If the data being deserialized is not a valid JSON document, a If the data being deserialized is not a valid JSON document, a
:exc:`JSONDecodeError` will be raised. :exc:`JSONDecodeError` will be raised.
.. versionchanged:: 3.6
All parameters are now :ref:`keyword-only <keyword-only_parameter>`.
.. method:: decode(s) .. method:: decode(s)
Return the Python representation of *s* (a :class:`str` instance Return the Python representation of *s* (a :class:`str` instance
...@@ -359,7 +368,7 @@ Encoders and Decoders ...@@ -359,7 +368,7 @@ Encoders and Decoders
extraneous data at the end. extraneous data at the end.
.. class:: JSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None) .. class:: JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Extensible JSON encoder for Python data structures. Extensible JSON encoder for Python data structures.
...@@ -438,6 +447,9 @@ Encoders and Decoders ...@@ -438,6 +447,9 @@ Encoders and Decoders
otherwise be serialized. It should return a JSON encodable version of the otherwise be serialized. It should return a JSON encodable version of the
object or raise a :exc:`TypeError`. object or raise a :exc:`TypeError`.
.. versionchanged:: 3.6
All parameters are now :ref:`keyword-only <keyword-only_parameter>`.
.. method:: default(o) .. method:: default(o)
......
...@@ -685,6 +685,14 @@ Changes in the Python API ...@@ -685,6 +685,14 @@ Changes in the Python API
Code that has already been updated in accordance with the deprecation Code that has already been updated in accordance with the deprecation
warning generated by 3.5 will not be affected. warning generated by 3.5 will not be affected.
* All optional parameters of the :func:`~json.dump`, :func:`~json.dumps`,
:func:`~json.load` and :func:`~json.loads` functions and
:class:`~json.JSONEncoder` and :class:`~json.JSONDecoder` class
constructors in the :mod:`json` module are now :ref:`keyword-only
<keyword-only_parameter>`.
(Contributed by Serhiy Storchaka in :issue:`18726`.)
Changes in the C API Changes in the C API
-------------------- --------------------
......
...@@ -116,7 +116,7 @@ _default_encoder = JSONEncoder( ...@@ -116,7 +116,7 @@ _default_encoder = JSONEncoder(
default=None, default=None,
) )
def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, def dump(obj, fp, *, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None, allow_nan=True, cls=None, indent=None, separators=None,
default=None, sort_keys=False, **kw): default=None, sort_keys=False, **kw):
"""Serialize ``obj`` as a JSON formatted stream to ``fp`` (a """Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
...@@ -179,7 +179,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, ...@@ -179,7 +179,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
fp.write(chunk) fp.write(chunk)
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, def dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None, allow_nan=True, cls=None, indent=None, separators=None,
default=None, sort_keys=False, **kw): default=None, sort_keys=False, **kw):
"""Serialize ``obj`` to a JSON formatted ``str``. """Serialize ``obj`` to a JSON formatted ``str``.
...@@ -240,7 +240,7 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, ...@@ -240,7 +240,7 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
_default_decoder = JSONDecoder(object_hook=None, object_pairs_hook=None) _default_decoder = JSONDecoder(object_hook=None, object_pairs_hook=None)
def load(fp, cls=None, object_hook=None, parse_float=None, def load(fp, *, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, **kw): parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
a JSON document) to a Python object. a JSON document) to a Python object.
...@@ -268,7 +268,7 @@ def load(fp, cls=None, object_hook=None, parse_float=None, ...@@ -268,7 +268,7 @@ def load(fp, cls=None, object_hook=None, parse_float=None,
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) 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, *, encoding=None, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None, **kw): parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):
"""Deserialize ``s`` (a ``str`` instance containing a JSON """Deserialize ``s`` (a ``str`` instance containing a JSON
document) to a Python object. document) to a Python object.
......
...@@ -280,7 +280,7 @@ class JSONDecoder(object): ...@@ -280,7 +280,7 @@ class JSONDecoder(object):
""" """
def __init__(self, object_hook=None, parse_float=None, def __init__(self, *, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, strict=True, parse_int=None, parse_constant=None, strict=True,
object_pairs_hook=None): object_pairs_hook=None):
"""``object_hook``, if specified, will be called with the result """``object_hook``, if specified, will be called with the result
......
...@@ -101,7 +101,7 @@ class JSONEncoder(object): ...@@ -101,7 +101,7 @@ class JSONEncoder(object):
""" """
item_separator = ', ' item_separator = ', '
key_separator = ': ' key_separator = ': '
def __init__(self, skipkeys=False, ensure_ascii=True, def __init__(self, *, skipkeys=False, ensure_ascii=True,
check_circular=True, allow_nan=True, sort_keys=False, check_circular=True, allow_nan=True, sort_keys=False,
indent=None, separators=None, default=None): indent=None, separators=None, default=None):
"""Constructor for JSONEncoder, with sensible defaults. """Constructor for JSONEncoder, with sensible defaults.
......
...@@ -10,6 +10,10 @@ What's New in Python 3.6.0 alpha 3 ...@@ -10,6 +10,10 @@ What's New in Python 3.6.0 alpha 3
Library Library
------- -------
- Issue #18726: All optional parameters of the dump(), dumps(),
load() and loads() functions and JSONEncoder and JSONDecoder class
constructors in the json module are now keyword-only.
- Issue #27319: Methods selection_set(), selection_add(), selection_remove() - Issue #27319: Methods selection_set(), selection_add(), selection_remove()
and selection_toggle() of ttk.TreeView now allow passing multiple items as and selection_toggle() of ttk.TreeView now allow passing multiple items as
multiple arguments instead of passing them as a tuple. Deprecated multiple arguments instead of passing them as a tuple. Deprecated
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment