Skip to content

Commit c8284cf

Browse files
committed
#9087: update json docstrings -- unicode and long do not exist anymore.
1 parent 8477f82 commit c8284cf

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

Lib/json/__init__.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
125125
``.write()``-supporting file-like object).
126126
127127
If ``skipkeys`` is true then ``dict`` keys that are not basic types
128-
(``str``, ``unicode``, ``int``, ``float``, ``bool``, ``None``) will be
129-
skipped instead of raising a ``TypeError``.
128+
(``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
129+
instead of raising a ``TypeError``.
130130
131-
If ``ensure_ascii`` is false, then the some chunks written to ``fp``
132-
may be ``unicode`` instances, subject to normal Python ``str`` to
133-
``unicode`` coercion rules. Unless ``fp.write()`` explicitly
134-
understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
135-
to cause an error.
131+
If ``ensure_ascii`` is false, then the strings written to ``fp`` can
132+
contain non-ASCII characters if they appear in strings contained in
133+
``obj``. Otherwise, all such characters are escaped in JSON strings.
136134
137135
If ``check_circular`` is false, then the circular reference check
138136
for container types will be skipped and a circular reference will
@@ -185,12 +183,12 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
185183
"""Serialize ``obj`` to a JSON formatted ``str``.
186184
187185
If ``skipkeys`` is false then ``dict`` keys that are not basic types
188-
(``str``, ``unicode``, ``int``, ``float``, ``bool``, ``None``) will be
189-
skipped instead of raising a ``TypeError``.
186+
(``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
187+
instead of raising a ``TypeError``.
190188
191-
If ``ensure_ascii`` is false, then the return value will be a
192-
``unicode`` instance subject to normal Python ``str`` to ``unicode``
193-
coercion rules instead of being escaped to an ASCII ``str``.
189+
If ``ensure_ascii`` is false, then the return value can contain non-ASCII
190+
characters if they appear in strings contained in ``obj``. Otherwise, all
191+
such characters are escaped in JSON strings.
194192
195193
If ``check_circular`` is false, then the circular reference check
196194
for container types will be skipped and a circular reference will

Lib/json/decoder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ class JSONDecoder(object):
263263
+---------------+-------------------+
264264
| array | list |
265265
+---------------+-------------------+
266-
| string | unicode |
266+
| string | str |
267267
+---------------+-------------------+
268-
| number (int) | int, long |
268+
| number (int) | int |
269269
+---------------+-------------------+
270270
| number (real) | float |
271271
+---------------+-------------------+
@@ -318,8 +318,8 @@ def __init__(self, object_hook=None, parse_float=None,
318318

319319

320320
def decode(self, s, _w=WHITESPACE.match):
321-
"""Return the Python representation of ``s`` (a ``str`` or ``unicode``
322-
instance containing a JSON document)
321+
"""Return the Python representation of ``s`` (a ``str`` instance
322+
containing a JSON document).
323323
324324
"""
325325
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
@@ -329,8 +329,8 @@ def decode(self, s, _w=WHITESPACE.match):
329329
return obj
330330

331331
def raw_decode(self, s, idx=0):
332-
"""Decode a JSON document from ``s`` (a ``str`` or ``unicode``
333-
beginning with a JSON document) and return a 2-tuple of the Python
332+
"""Decode a JSON document from ``s`` (a ``str`` beginning with
333+
a JSON document) and return a 2-tuple of the Python
334334
representation and the index in ``s`` where the document ended.
335335
336336
This can be used to decode a JSON document from a string that may

Lib/json/encoder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class JSONEncoder(object):
7777
+-------------------+---------------+
7878
| list, tuple | array |
7979
+-------------------+---------------+
80-
| str, unicode | string |
80+
| str | string |
8181
+-------------------+---------------+
82-
| int, long, float | number |
82+
| int, float | number |
8383
+-------------------+---------------+
8484
| True | true |
8585
+-------------------+---------------+
@@ -102,12 +102,12 @@ def __init__(self, skipkeys=False, ensure_ascii=True,
102102
"""Constructor for JSONEncoder, with sensible defaults.
103103
104104
If skipkeys is false, then it is a TypeError to attempt
105-
encoding of keys that are not str, int, long, float or None. If
105+
encoding of keys that are not str, int, float or None. If
106106
skipkeys is True, such items are simply skipped.
107107
108108
If ensure_ascii is true, the output is guaranteed to be str
109-
objects with all incoming unicode characters escaped. If
110-
ensure_ascii is false, the output will be unicode object.
109+
objects with all incoming non-ASCII characters escaped. If
110+
ensure_ascii is false, the output can contain non-ASCII characters.
111111
112112
If check_circular is true, then lists, dicts, and custom encoded
113113
objects will be checked for circular references during encoding to

Modules/_json.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
484484
}
485485

486486
PyDoc_STRVAR(pydoc_scanstring,
487-
"scanstring(basestring, end, strict=True) -> (bytes, end)\n"
487+
"scanstring(string, end, strict=True) -> (string, end)\n"
488488
"\n"
489489
"Scan the string s for a JSON string. End is the index of the\n"
490490
"character in s after the quote that started the JSON string.\n"
@@ -512,15 +512,15 @@ py_scanstring(PyObject* self UNUSED, PyObject *args)
512512
}
513513
else {
514514
PyErr_Format(PyExc_TypeError,
515-
"first argument must be a string or bytes, not %.80s",
515+
"first argument must be a string, not %.80s",
516516
Py_TYPE(pystr)->tp_name);
517517
return NULL;
518518
}
519519
return _build_rval_index_tuple(rval, next_end);
520520
}
521521

522522
PyDoc_STRVAR(pydoc_encode_basestring_ascii,
523-
"encode_basestring_ascii(basestring) -> bytes\n"
523+
"encode_basestring_ascii(string) -> string\n"
524524
"\n"
525525
"Return an ASCII-only JSON representation of a Python string"
526526
);

0 commit comments

Comments
 (0)