From 139bc588e135569bf352ed638ec54b1b3225efc3 Mon Sep 17 00:00:00 2001 From: Zac Hatfield-Dodds Date: Mon, 7 Aug 2023 23:48:20 -0700 Subject: [PATCH] pprint empty flag combinations https: //github.com/HypothesisWorks/hypothesis/pull/3710#discussion_r1285467133 Co-Authored-By: Joachim B Haga --- hypothesis-python/RELEASE.rst | 4 ++++ hypothesis-python/src/hypothesis/vendor/pretty.py | 5 ++++- hypothesis-python/tests/cover/test_pretty.py | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 hypothesis-python/RELEASE.rst diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..1a9b29ba74 --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -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. diff --git a/hypothesis-python/src/hypothesis/vendor/pretty.py b/hypothesis-python/src/hypothesis/vendor/pretty.py index 3ef2ab3771..b9158573eb 100644 --- a/hypothesis-python/src/hypothesis/vendor/pretty.py +++ b/hypothesis-python/src/hypothesis/vendor/pretty.py @@ -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}") diff --git a/hypothesis-python/tests/cover/test_pretty.py b/hypothesis-python/tests/cover/test_pretty.py index d02e2691ab..2497c16db3 100644 --- a/hypothesis-python/tests/cover/test_pretty.py +++ b/hypothesis-python/tests/cover/test_pretty.py @@ -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",