pprint: Remove the option to sort dictionaries, we always do it
This commit is contained in:
parent
03b24e5b30
commit
6aa35f772f
|
@ -65,7 +65,6 @@ class PrettyPrinter:
|
||||||
width: int = 80,
|
width: int = 80,
|
||||||
depth: Optional[int] = None,
|
depth: Optional[int] = None,
|
||||||
*,
|
*,
|
||||||
sort_dicts: bool = True,
|
|
||||||
underscore_numbers: bool = False,
|
underscore_numbers: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle pretty printing operations onto a stream using a set of
|
"""Handle pretty printing operations onto a stream using a set of
|
||||||
|
@ -80,9 +79,6 @@ class PrettyPrinter:
|
||||||
depth
|
depth
|
||||||
The maximum depth to print out nested structures.
|
The maximum depth to print out nested structures.
|
||||||
|
|
||||||
sort_dicts
|
|
||||||
If true, dict keys are sorted.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
indent = int(indent)
|
indent = int(indent)
|
||||||
width = int(width)
|
width = int(width)
|
||||||
|
@ -95,7 +91,6 @@ class PrettyPrinter:
|
||||||
self._depth = depth
|
self._depth = depth
|
||||||
self._indent_per_level = indent
|
self._indent_per_level = indent
|
||||||
self._width = width
|
self._width = width
|
||||||
self._sort_dicts = sort_dicts
|
|
||||||
self._underscore_numbers = underscore_numbers
|
self._underscore_numbers = underscore_numbers
|
||||||
|
|
||||||
def pformat(self, object: Any) -> str:
|
def pformat(self, object: Any) -> str:
|
||||||
|
@ -174,10 +169,7 @@ class PrettyPrinter:
|
||||||
) -> None:
|
) -> None:
|
||||||
write = stream.write
|
write = stream.write
|
||||||
write("{")
|
write("{")
|
||||||
if self._sort_dicts:
|
items = sorted(object.items(), key=_safe_tuple)
|
||||||
items = sorted(object.items(), key=_safe_tuple)
|
|
||||||
else:
|
|
||||||
items = object.items()
|
|
||||||
self._format_dict_items(items, stream, indent, allowance, context, level)
|
self._format_dict_items(items, stream, indent, allowance, context, level)
|
||||||
write("}")
|
write("}")
|
||||||
|
|
||||||
|
@ -629,11 +621,7 @@ class PrettyPrinter:
|
||||||
components: List[str] = []
|
components: List[str] = []
|
||||||
append = components.append
|
append = components.append
|
||||||
level += 1
|
level += 1
|
||||||
if self._sort_dicts:
|
for k, v in sorted(object.items(), key=_safe_tuple):
|
||||||
items = sorted(object.items(), key=_safe_tuple)
|
|
||||||
else:
|
|
||||||
items = object.items()
|
|
||||||
for k, v in items:
|
|
||||||
krepr = self._safe_repr(k, context, maxlevels, level)
|
krepr = self._safe_repr(k, context, maxlevels, level)
|
||||||
vrepr = self._safe_repr(v, context, maxlevels, level)
|
vrepr = self._safe_repr(v, context, maxlevels, level)
|
||||||
append(f"{krepr}: {vrepr}")
|
append(f"{krepr}: {vrepr}")
|
||||||
|
|
Loading…
Reference in New Issue