[Python-checkins] cpython: Issue #18726: All optional parameters of the dump(), dumps(),

serhiy.storchaka python-checkins at python.org
Tue Jun 21 17:03:54 EDT 2016


https://hg.python.org/cpython/rev/db5fe5c4d09d
changeset: 102116:db5fe5c4d09d
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Jun 22 00:03:20 2016 +0300
summary:
 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.
files:
 Doc/library/json.rst | 24 ++++++++++++++++++------
 Doc/whatsnew/3.6.rst | 8 ++++++++
 Lib/json/__init__.py | 8 ++++----
 Lib/json/decoder.py | 2 +-
 Lib/json/encoder.py | 2 +-
 Misc/NEWS | 4 ++++
 6 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -126,7 +126,7 @@
 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, \
 indent=None, separators=None, default=None, \
 sort_keys=False, **kw)
@@ -184,8 +184,11 @@
 :meth:`default` method to serialize additional types), specify it with the
 *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, \
 indent=None, separators=None, default=None, \
 sort_keys=False, **kw)
@@ -209,7 +212,7 @@
 the original one. That is, ``loads(dumps(x)) != x`` if x has non-string
 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`
 containing a JSON document) to a Python object using this :ref:`conversion
@@ -257,7 +260,10 @@
 If the data being deserialized is not a valid JSON document, a
 :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
 Python object using this :ref:`conversion table <json-to-py-table>`.
@@ -271,7 +277,7 @@
 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.
 
@@ -341,6 +347,9 @@
 If the data being deserialized is not a valid JSON document, a
 :exc:`JSONDecodeError` will be raised.
 
+ .. versionchanged:: 3.6
+ All parameters are now :ref:`keyword-only <keyword-only_parameter>`.
+
 .. method:: decode(s)
 
 Return the Python representation of *s* (a :class:`str` instance
@@ -359,7 +368,7 @@
 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.
 
@@ -438,6 +447,9 @@
 otherwise be serialized. It should return a JSON encodable version of the
 object or raise a :exc:`TypeError`.
 
+ .. versionchanged:: 3.6
+ All parameters are now :ref:`keyword-only <keyword-only_parameter>`.
+
 
 .. method:: default(o)
 
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -685,6 +685,14 @@
 Code that has already been updated in accordance with the deprecation
 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
 --------------------
 
diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py
--- a/Lib/json/__init__.py
+++ b/Lib/json/__init__.py
@@ -116,7 +116,7 @@
 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,
 default=None, sort_keys=False, **kw):
 """Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
@@ -179,7 +179,7 @@
 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,
 default=None, sort_keys=False, **kw):
 """Serialize ``obj`` to a JSON formatted ``str``.
@@ -240,7 +240,7 @@
 _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):
 """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
 a JSON document) to a Python object.
@@ -268,7 +268,7 @@
 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):
 """Deserialize ``s`` (a ``str`` instance containing a JSON
 document) to a Python object.
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -280,7 +280,7 @@
 
 """
 
- 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,
 object_pairs_hook=None):
 """``object_hook``, if specified, will be called with the result
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -101,7 +101,7 @@
 """
 item_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,
 indent=None, separators=None, default=None):
 """Constructor for JSONEncoder, with sensible defaults.
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
 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()
 and selection_toggle() of ttk.TreeView now allow passing multiple items as
 multiple arguments instead of passing them as a tuple. Deprecated
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /