Skip to content

Commit 3b90747

Browse files
authored
Merge pull request #3715 from Zac-HD/enum-reprs
2 parents 1b2375b + 139bc58 commit 3b90747

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

hypothesis-python/RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
We can now pretty-print combinations of *zero* :class:`enum.Flag`
4+
values, like ``SomeFlag(0)``, which has never worked before.

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,10 @@ def _repr_dataframe(obj, p, cycle): # pragma: no cover
804804
def _repr_enum(obj, p, cycle):
805805
tname = type(obj).__name__
806806
if isinstance(obj, Flag):
807-
p.text(" | ".join(f"{tname}.{x.name}" for x in type(obj) if x & obj == x))
807+
p.text(
808+
" | ".join(f"{tname}.{x.name}" for x in type(obj) if x & obj == x)
809+
or f"{tname}({obj.value!r})" # if no matching members
810+
)
808811
else:
809812
p.text(f"{tname}.{obj.name}")
810813

hypothesis-python/tests/cover/test_pretty.py

+1
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ def __repr__(self):
657657
"Options.A",
658658
"Options.A | Options.B",
659659
"Options.A | Options.B | Options.C",
660+
"Options(0)",
660661
"EvilReprOptions.A",
661662
"LyingReprOptions.A",
662663
"EvilReprOptions.A | EvilReprOptions.B",

0 commit comments

Comments
 (0)