Skip to content

Commit

Permalink
More known-filter-predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Oct 17, 2022
1 parent 945ee47 commit bea95f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

This patch teaches :func:`~hypothesis.strategies.text` to rewrite a few more
filter predicates (:issue:`3134`). You're unlikely to notice any change.
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ def __repr__(self):
# See https://docs.python.org/3/library/stdtypes.html#string-methods
# These methods always return Truthy values for any nonempty string.
_nonempty_filters = ListStrategy._nonempty_filters + (
str,
str.capitalize,
str.casefold,
str.encode,
str.expandtabs,
str.join,
str.lower,
str.rsplit,
str.split,
str.splitlines,
str.swapcase,
Expand All @@ -144,6 +147,9 @@ def __repr__(self):
str.isnumeric,
str.isspace,
str.istitle,
str.lstrip,
str.rstrip,
str.strip,
)

def filter(self, condition):
Expand All @@ -156,9 +162,6 @@ def filter(self, condition):
# We use ListStrategy filter logic for the conditions that *only* imply
# the string is nonempty. Here, we increment the min_size but still apply
# the filter for conditions that imply nonempty *and specific contents*.
#
# TODO: we may eventually rewrite the elements_strategy for some of these,
# avoiding rejection sampling and making them much more efficient.
if condition in self._nonempty_and_content_filters:
assert self.max_size >= 1, "Always-empty is special cased in st.text()"
self = copy.copy(self)
Expand Down

0 comments on commit bea95f0

Please sign in to comment.