Skip to content

Commit bea95f0

Browse files
committed
More known-filter-predicates
1 parent 945ee47 commit bea95f0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
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+
This patch teaches :func:`~hypothesis.strategies.text` to rewrite a few more
4+
filter predicates (:issue:`3134`). You're unlikely to notice any change.

hypothesis-python/src/hypothesis/strategies/_internal/strings.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ def __repr__(self):
121121
# See https://docs.python.org/3/library/stdtypes.html#string-methods
122122
# These methods always return Truthy values for any nonempty string.
123123
_nonempty_filters = ListStrategy._nonempty_filters + (
124+
str,
124125
str.capitalize,
125126
str.casefold,
127+
str.encode,
126128
str.expandtabs,
127129
str.join,
128130
str.lower,
131+
str.rsplit,
129132
str.split,
130133
str.splitlines,
131134
str.swapcase,
@@ -144,6 +147,9 @@ def __repr__(self):
144147
str.isnumeric,
145148
str.isspace,
146149
str.istitle,
150+
str.lstrip,
151+
str.rstrip,
152+
str.strip,
147153
)
148154

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

0 commit comments

Comments
 (0)