diff options
| author | robot-piglet <[email protected]> | 2026-05-27 21:50:51 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2026-05-27 22:12:32 +0300 |
| commit | fe0d7e76a02da0c8870a13b4d3cb13a919c584f7 (patch) | |
| tree | 4afccfb0e372a87ae3d7b0c721216afee0c860ab /contrib/python/hypothesis | |
| parent | ea32001651a31d552b8ac50da92a631fbb4e5cfc (diff) | |
Intermediate changes
commit_hash:fe0f760ce1e1bc10a09e0830e07f4f99c11aa114
Diffstat (limited to 'contrib/python/hypothesis')
5 files changed, 50 insertions, 11 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA index 4bb4b728a00..21754a6e162 100644 --- a/contrib/python/hypothesis/py3/.dist-info/METADATA +++ b/contrib/python/hypothesis/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.4 Name: hypothesis -Version: 6.152.6 +Version: 6.152.7 Summary: The property-based testing library for Python Author-email: "David R. MacIver and Zac Hatfield-Dodds" <[email protected]> License-Expression: MPL-2.0 diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/collections.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/collections.py index 7a604bb8833..7f395e08cd6 100644 --- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/collections.py +++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/collections.py @@ -11,7 +11,7 @@ import copy import math from collections.abc import Callable, Iterable -from typing import Any, overload +from typing import Any, TypeGuard, overload from hypothesis import strategies as st from hypothesis.control import current_build_context @@ -232,7 +232,15 @@ class ListStrategy(SearchStrategy[list[Ex]]): f"min_size={self.min_size:_}, max_size={self.max_size:_})" ) - def filter(self, condition: Callable[[list[Ex]], Any]) -> SearchStrategy[list[Ex]]: + @overload + def filter( + self, condition: Callable[[list[Ex]], TypeGuard[T]] + ) -> "SearchStrategy[T]": ... + @overload + def filter( + self, condition: Callable[[list[Ex]], Any] + ) -> "SearchStrategy[list[Ex]]": ... + def filter(self, condition): if condition in self._nonempty_filters or is_identity_function(condition): assert self.max_size >= 1, "Always-empty is special cased in st.lists()" if self.min_size >= 1: diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/strategies.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/strategies.py index a9bf7393861..de6a9cb7ffb 100644 --- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/strategies.py +++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/strategies.py @@ -24,6 +24,7 @@ from typing import ( Generic, Literal, TypeAlias, + TypeGuard, TypeVar, cast, overload, @@ -414,7 +415,13 @@ class SearchStrategy(Generic[Ex]): # entire Callable[[Ex], Any] expression rather than use a type alias. # TypeAlias is *not* simply a macro that inserts the text. TypeAlias will not # reference the local TypeVar context. - def filter(self, condition: Callable[[Ex], Any]) -> "SearchStrategy[Ex]": + @overload + def filter( + self, condition: Callable[[Ex], TypeGuard[T]] + ) -> "SearchStrategy[T]": ... + @overload + def filter(self, condition: Callable[[Ex], Any]) -> "SearchStrategy[Ex]": ... + def filter(self, condition): """Returns a new strategy that generates values from this strategy which satisfy the provided condition. @@ -597,7 +604,13 @@ class SampledFromStrategy(SearchStrategy[Ex]): # guaranteed by the ("map", pack) transformation return cast(SearchStrategy[T], s) - def filter(self, condition: Callable[[Ex], Any]) -> SearchStrategy[Ex]: + @overload + def filter( + self, condition: Callable[[Ex], TypeGuard[T]] + ) -> "SearchStrategy[T]": ... + @overload + def filter(self, condition: Callable[[Ex], Any]) -> "SearchStrategy[Ex]": ... + def filter(self, condition): return type(self)( self.elements, force_repr=self.force_repr, @@ -654,7 +667,7 @@ class SampledFromStrategy(SearchStrategy[Ex]): # The worst case performance of this scheme is # itertools.chain(range(2**100), [st.none()]), where it degrades to # hashing every int in the range. - (elements_is_hashable, hash_value) = _is_hashable(self.elements) + elements_is_hashable, hash_value = _is_hashable(self.elements) if isinstance(self.elements, range) or ( elements_is_hashable and not any(isinstance(e, SearchStrategy) for e in self.elements) @@ -873,7 +886,13 @@ class OneOfStrategy(SearchStrategy[Ex]): else: return [self] - def filter(self, condition: Callable[[Ex], Any]) -> SearchStrategy[Ex]: + @overload + def filter( + self, condition: Callable[[Ex], TypeGuard[T]] + ) -> "SearchStrategy[T]": ... + @overload + def filter(self, condition: Callable[[Ex], Any]) -> "SearchStrategy[Ex]": ... + def filter(self, condition): return FilteredStrategy( OneOfStrategy([s.filter(condition) for s in self.original_strategies]), conditions=(), @@ -1039,9 +1058,15 @@ class MappedStrategy(SearchStrategy[MappedTo], Generic[MappedFrom, MappedTo]): for strategy in self.mapped_strategy.branches ] + @overload + def filter( + self, condition: Callable[[MappedTo], TypeGuard[T]] + ) -> "SearchStrategy[T]": ... + @overload def filter( self, condition: Callable[[MappedTo], Any] - ) -> "SearchStrategy[MappedTo]": + ) -> "SearchStrategy[MappedTo]": ... + def filter(self, condition): # Includes a special case so that we can rewrite filters on collection # lengths, when most collections are `st.lists(...).map(the_type)`. ListStrategy = _list_strategy_type() @@ -1161,7 +1186,13 @@ class FilteredStrategy(SearchStrategy[Ex]): # an in-place method so we still just re-initialize the strategy! FilteredStrategy.__init__(self, fresh, ()) - def filter(self, condition: Callable[[Ex], Any]) -> "FilteredStrategy[Ex]": + @overload + def filter( + self, condition: Callable[[Ex], TypeGuard[T]] + ) -> "FilteredStrategy[T]": ... + @overload + def filter(self, condition: Callable[[Ex], Any]) -> "FilteredStrategy[Ex]": ... + def filter(self, condition): # If we can, it's more efficient to rewrite our strategy to satisfy the # condition. We therefore exploit the fact that the order of predicates # doesn't matter (`f(x) and g(x) == g(x) and f(x)`) by attempting to apply diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py index 5994b35ebfc..38877a283a1 100644 --- a/contrib/python/hypothesis/py3/hypothesis/version.py +++ b/contrib/python/hypothesis/py3/hypothesis/version.py @@ -8,5 +8,5 @@ # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at https://mozilla.org/MPL/2.0/. -__version_info__ = (6, 152, 6) +__version_info__ = (6, 152, 7) __version__ = ".".join(map(str, __version_info__)) diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make index 084316a1c7a..e40304836ab 100644 --- a/contrib/python/hypothesis/py3/ya.make +++ b/contrib/python/hypothesis/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(6.152.6) +VERSION(6.152.7) LICENSE(MPL-2.0) |
