Skip to content

Commit 0f5c68e

Browse files
Remove sorting of dictionaries in pretty.printer. #3370
Order of dictionaries is now enforced in Python 3.7 and higher. This means that the original order of dictionaries matters for falsifying examples.
1 parent a11ec6f commit 0f5c68e

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

hypothesis-python/src/hypothesis/vendor/pretty.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,7 @@ def inner(obj, p, cycle):
603603
if cycle:
604604
return p.text("{...}")
605605
p.begin_group(1, start)
606-
keys = obj.keys()
607-
# if dict isn't large enough to be truncated, sort keys before
608-
# displaying
609-
if not (p.max_seq_length and len(obj) >= p.max_seq_length):
610-
try:
611-
keys = sorted(keys)
612-
except Exception:
613-
# Sometimes the keys don't sort.
614-
pass
615-
for idx, key in p._enumerate(keys):
606+
for idx, key in p._enumerate(obj):
616607
if idx:
617608
p.text(",")
618609
p.breakable()

hypothesis-python/tests/cover/test_pretty.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def test_list():
134134
def test_dict():
135135
assert pretty.pretty({}) == "{}"
136136
assert pretty.pretty({1: 1}) == "{1: 1}"
137+
assert pretty.pretty({1: 1, 0: 0}) == "{1: 1, 0: 0}"
137138

138139

139140
def test_tuple():

0 commit comments

Comments
 (0)