Skip to content

Commit 139bc58

Browse files
Zac-HDjobh
andcommitted
pprint empty flag combinations
https: //github.com//pull/3710#discussion_r1285467133 Co-Authored-By: Joachim B Haga <[email protected]>
1 parent 1b2375b commit 139bc58

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 4 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)