Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d16ee63d
Commit
d16ee63d
authored
Apr 12, 2011
by
R David Murray
Browse files
Options
Browse Files
Download
Plain Diff
Merge #10019: Fix regression relative to 2.6: add newlines if indent=0
Patch by Amaury Forgeot d'Arc, updated by Sando Tosi.
parents
59c90c6c
d5315482
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
5 deletions
+24
-5
Doc/library/json.rst
Doc/library/json.rst
+4
-4
Lib/json/encoder.py
Lib/json/encoder.py
+1
-1
Lib/test/json_tests/test_indent.py
Lib/test/json_tests/test_indent.py
+16
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/json.rst
View file @
d16ee63d
...
@@ -136,10 +136,10 @@ Basic Usage
...
@@ -136,10 +136,10 @@ Basic Usage
If *indent* is a non-negative integer or string, then JSON array elements and
If *indent* is a non-negative integer or string, then JSON array elements and
object members will be pretty-printed with that indent level. An indent level
object members will be pretty-printed with that indent level. An indent level
of 0
or ``""`` will only insert newlines. ``None`` (the default) selects the
of 0
, negative, or ``""`` will only insert newlines. ``None`` (the default)
most compact representation. Using an integer indent indents that many spaces
selects the most compact representation. Using a positive integer indent
per level. If *indent* is a string (such at '\t'), that string is used to indent
indents that many spaces per level. If *indent* is a string (such at '\t'),
each level.
that string is used to indent
each level.
If *separators* is an ``(item_separator, dict_separator)`` tuple, then it
If *separators* is an ``(item_separator, dict_separator)`` tuple, then it
will be used instead of the default ``(', ', ': ')`` separators. ``(',',
will be used instead of the default ``(', ', ': ')`` separators. ``(',',
...
...
Lib/json/encoder.py
View file @
d16ee63d
...
@@ -233,7 +233,7 @@ class JSONEncoder(object):
...
@@ -233,7 +233,7 @@ class JSONEncoder(object):
if (_one_shot and c_make_encoder is not None
if (_one_shot and c_make_encoder is not None
and
not self.indent
):
and
self.indent is None
):
_iterencode = c_make_encoder(
_iterencode = c_make_encoder(
markers, self.default, _encoder, self.indent,
markers, self.default, _encoder, self.indent,
self.key_separator, self.item_separator, self.sort_keys,
self.key_separator, self.item_separator, self.sort_keys,
...
...
Lib/test/json_tests/test_indent.py
View file @
d16ee63d
...
@@ -2,6 +2,7 @@ from unittest import TestCase
...
@@ -2,6 +2,7 @@ from unittest import TestCase
import
json
import
json
import
textwrap
import
textwrap
from
io
import
StringIO
class
TestIndent
(
TestCase
):
class
TestIndent
(
TestCase
):
def
test_indent
(
self
):
def
test_indent
(
self
):
...
@@ -43,3 +44,18 @@ class TestIndent(TestCase):
...
@@ -43,3 +44,18 @@ class TestIndent(TestCase):
self
.
assertEqual
(
h3
,
h
)
self
.
assertEqual
(
h3
,
h
)
self
.
assertEqual
(
d2
,
expect
.
expandtabs
(
2
))
self
.
assertEqual
(
d2
,
expect
.
expandtabs
(
2
))
self
.
assertEqual
(
d3
,
expect
)
self
.
assertEqual
(
d3
,
expect
)
def
test_indent0
(
self
):
h
=
{
3
:
1
}
def
check
(
indent
,
expected
):
d1
=
json
.
dumps
(
h
,
indent
=
indent
)
self
.
assertEqual
(
d1
,
expected
)
sio
=
StringIO
()
json
.
dump
(
h
,
sio
,
indent
=
indent
)
self
.
assertEqual
(
sio
.
getvalue
(),
expected
)
# indent=0 should emit newlines
check
(
0
,
'{
\
n
"3": 1
\
n
}'
)
# indent=None is more compact
check
(
None
,
'{"3": 1}'
)
Misc/NEWS
View file @
d16ee63d
...
@@ -103,6 +103,9 @@ Core and Builtins
...
@@ -103,6 +103,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10019: Fixed regression in json module where an indent of 0 stopped
adding newlines and acted instead like '
None
'.
- Issue #11186: pydoc ignores a module if its name contains a surrogate
- Issue #11186: pydoc ignores a module if its name contains a surrogate
character in the index of modules.
character in the index of modules.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment