Skip to content

Commit

Permalink
Merge pull request #3715 from Zac-HD/enum-reprs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD authored Aug 8, 2023
2 parents 1b2375b + 139bc58 commit 3b90747
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

We can now pretty-print combinations of *zero* :class:`enum.Flag`
values, like ``SomeFlag(0)``, which has never worked before.
5 changes: 4 additions & 1 deletion hypothesis-python/src/hypothesis/vendor/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,10 @@ def _repr_dataframe(obj, p, cycle): # pragma: no cover
def _repr_enum(obj, p, cycle):
tname = type(obj).__name__
if isinstance(obj, Flag):
p.text(" | ".join(f"{tname}.{x.name}" for x in type(obj) if x & obj == x))
p.text(
" | ".join(f"{tname}.{x.name}" for x in type(obj) if x & obj == x)
or f"{tname}({obj.value!r})" # if no matching members
)
else:
p.text(f"{tname}.{obj.name}")

Expand Down
1 change: 1 addition & 0 deletions hypothesis-python/tests/cover/test_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ def __repr__(self):
"Options.A",
"Options.A | Options.B",
"Options.A | Options.B | Options.C",
"Options(0)",
"EvilReprOptions.A",
"LyingReprOptions.A",
"EvilReprOptions.A | EvilReprOptions.B",
Expand Down

0 comments on commit 3b90747

Please sign in to comment.