You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2701 proposed "rewriting" filters in simple cases, i.e. modifying the strategies to satisfy the condition by construction rather than rejection sampling. We shipped this for numeric comparisons, as well as some string methods and float properties like isnan, and it's been working well!
Following #3780, we'd like a way to do filter-rewriting for length filters.
as an extension, using AST analysis to cover e.g. lambda ls: 0 < len(ls) <= 10 - in this case we'll want to apply the rewrite for efficiency, and apply the predicate as a filter in case the name len has been rebound in the enclosing scope.
support st.lists(...).map(some_collection_type), in order to handle st.sets(), st.binary(), st.dictionaries(), and similar user-defined strategies (including .map(tuple), which is returned by st.from_type(tuple[T, ...])).
it's probably better to handle this in ListStrategy.map than in MappedStrategy.filter? Gonna be an inelegant hack either way, but the results should be worth it.
There have also been a variety of further filtering extensions proposed in older issues, which I'm listing here in case someone would like to implement one of them. Note however that they're lower priority, so unless someone has explicitly volunteered I'll close this issue when the length filters are done.
Comparing elements of tuples() or fixed_dictionaries() to constants, like lambda d: 1 <= d[0] <= 10, by pushing a filter down onto the specific element. If we use the partial(operator.x, value) syntax then the elements strategy will also rewrite itself too!
#2701 proposed "rewriting" filters in simple cases, i.e. modifying the strategies to satisfy the condition by construction rather than rejection sampling. We shipped this for numeric comparisons, as well as some string methods and float properties like isnan, and it's been working well!
Following #3780, we'd like a way to do filter-rewriting for length filters.
partial(min_len, x)
for the min_len and max_len functions in filtering.pylambda ls: 0 < len(ls) <= 10
- in this case we'll want to apply the rewrite for efficiency, and apply the predicate as a filter in case the namelen
has been rebound in the enclosing scope.st.lists(...).map(some_collection_type)
, in order to handlest.sets()
,st.binary()
,st.dictionaries()
, and similar user-defined strategies (including.map(tuple)
, which is returned byst.from_type(tuple[T, ...])
).ListStrategy.map
than inMappedStrategy.filter
? Gonna be an inelegant hack either way, but the results should be worth it.There have also been a variety of further filtering extensions proposed in older issues, which I'm listing here in case someone would like to implement one of them. Note however that they're lower priority, so unless someone has explicitly volunteered I'll close this issue when the length filters are done.
tuples()
orfixed_dictionaries()
to constants, likelambda d: 1 <= d[0] <= 10
, by pushing a filter down onto the specific element. If we use thepartial(operator.x, value)
syntax then the elements strategy will also rewrite itself too!st.from_regex()
strategy withalphabet=...
argument and filter-rewriting #3479 (comment),st.text()
/st.binary()
filtered withre.compile(...).find
/match
/fullmatch
st.from_regex()
with the same filters - note that this will require some upstream work ingreenery
; see also Usegreenery
andregex_transformer
to mergepattern
andpatternProperties
keywords python-jsonschema/hypothesis-jsonschema#85operator.contains
/x.__contains__
lambda x: x in (1, 2, 3)
into ast.sampled_from()
strategy, for simple types like integers and stringsThe text was updated successfully, but these errors were encountered: