Skip to content

Commit 6aa35f7

Browse files
pprint: Remove the option to sort dictionaries, we always do it
1 parent 03b24e5 commit 6aa35f7

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/_pytest/_io/pprint.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def __init__(
6565
width: int = 80,
6666
depth: Optional[int] = None,
6767
*,
68-
sort_dicts: bool = True,
6968
underscore_numbers: bool = False,
7069
) -> None:
7170
"""Handle pretty printing operations onto a stream using a set of
@@ -80,9 +79,6 @@ def __init__(
8079
depth
8180
The maximum depth to print out nested structures.
8281
83-
sort_dicts
84-
If true, dict keys are sorted.
85-
8682
"""
8783
indent = int(indent)
8884
width = int(width)
@@ -95,7 +91,6 @@ def __init__(
9591
self._depth = depth
9692
self._indent_per_level = indent
9793
self._width = width
98-
self._sort_dicts = sort_dicts
9994
self._underscore_numbers = underscore_numbers
10095

10196
def pformat(self, object: Any) -> str:
@@ -174,10 +169,7 @@ def _pprint_dict(
174169
) -> None:
175170
write = stream.write
176171
write("{")
177-
if self._sort_dicts:
178-
items = sorted(object.items(), key=_safe_tuple)
179-
else:
180-
items = object.items()
172+
items = sorted(object.items(), key=_safe_tuple)
181173
self._format_dict_items(items, stream, indent, allowance, context, level)
182174
write("}")
183175

@@ -629,11 +621,7 @@ def _safe_repr(
629621
components: List[str] = []
630622
append = components.append
631623
level += 1
632-
if self._sort_dicts:
633-
items = sorted(object.items(), key=_safe_tuple)
634-
else:
635-
items = object.items()
636-
for k, v in items:
624+
for k, v in sorted(object.items(), key=_safe_tuple):
637625
krepr = self._safe_repr(k, context, maxlevels, level)
638626
vrepr = self._safe_repr(v, context, maxlevels, level)
639627
append(f"{krepr}: {vrepr}")

0 commit comments

Comments
 (0)