summaryrefslogtreecommitdiffstats
path: root/contrib/python/hypothesis
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2026-01-19 12:40:13 +0300
committerrobot-piglet <[email protected]>2026-01-19 13:17:05 +0300
commitef22f23d3970c53a3641f03aa87893f6cd49bff5 (patch)
tree8e0f9c416b7aa9eb224366532aea285e9c6957cf /contrib/python/hypothesis
parentd58b08dfbe6d6a50b7b01eda4fb990a9cfdb2c2b (diff)
Intermediate changes
commit_hash:0cdb936337b75fb5b94e369f3df422e396ab25fd
Diffstat (limited to 'contrib/python/hypothesis')
-rw-r--r--contrib/python/hypothesis/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py14
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py68
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/version.py2
-rw-r--r--contrib/python/hypothesis/py3/ya.make2
5 files changed, 82 insertions, 6 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA
index 4e971deb7c3..e716851be16 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.148.11
+Version: 6.148.12
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/core.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py
index 5f3069fd050..5aaf0fe497e 100644
--- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py
+++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py
@@ -1348,6 +1348,16 @@ def _from_type(thing: type[Ex]) -> SearchStrategy[Ex]:
if strategy is not NotImplemented:
return strategy
return _from_type(thing.__value__) # type: ignore
+ if types.is_a_type_alias_type(origin := get_origin(thing)): # pragma: no cover
+ # Handle parametrized type aliases like `type A[T] = list[T]; thing = A[int]`.
+ # In this case, `thing` is a GenericAlias whose origin is a TypeAliasType.
+ #
+ # covered by 3.12+ tests.
+ if origin in types._global_type_lookup:
+ strategy = as_strategy(types._global_type_lookup[origin], thing)
+ if strategy is not NotImplemented:
+ return strategy
+ return _from_type(types.evaluate_type_alias_type(thing))
if types.is_a_union(thing):
args = sorted(thing.__args__, key=types.type_sorting_key) # type: ignore
return one_of([_from_type(t) for t in args])
@@ -1397,9 +1407,9 @@ def _from_type(thing: type[Ex]) -> SearchStrategy[Ex]:
return strategy
elif (
isinstance(thing, GenericAlias)
- and (to := get_origin(thing)) in types._global_type_lookup
+ and (origin := get_origin(thing)) in types._global_type_lookup
):
- strategy = as_strategy(types._global_type_lookup[to], thing)
+ strategy = as_strategy(types._global_type_lookup[origin], thing)
if strategy is not NotImplemented:
return strategy
except TypeError: # pragma: no cover
diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
index 9965bffe2c9..dae1691d151 100644
--- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
+++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
@@ -35,7 +35,12 @@ from types import FunctionType
from typing import TYPE_CHECKING, Any, NewType, get_args, get_origin
from hypothesis import strategies as st
-from hypothesis.errors import HypothesisWarning, InvalidArgument, ResolutionFailed
+from hypothesis.errors import (
+ HypothesisException,
+ HypothesisWarning,
+ InvalidArgument,
+ ResolutionFailed,
+)
from hypothesis.internal.compat import PYPY, BaseExceptionGroup, ExceptionGroup
from hypothesis.internal.conjecture.utils import many as conjecture_utils_many
from hypothesis.internal.filtering import max_len, min_len
@@ -252,6 +257,67 @@ def try_issubclass(thing, superclass):
return False
+def _evaluate_type_alias_type(thing, *, typevars): # pragma: no cover # 3.12+
+ if isinstance(thing, typing.TypeVar):
+ if thing not in typevars:
+ raise ValueError(
+ f"Cannot look up value for unbound type var {thing}. "
+ f"Bound typevars: {typevars}"
+ )
+ return typevars[thing]
+
+ origin = get_origin(thing)
+ if origin is None:
+ # not a parametrized type, so nothing to substitute.
+ return thing
+
+ args = get_args(thing)
+ # we had an origin, so we must have an args
+ # note: I'm only mostly confident this is true and there may be a subtle
+ # violator.
+ assert args
+
+ concrete_args = tuple(
+ _evaluate_type_alias_type(arg, typevars=typevars) for arg in args
+ )
+ if isinstance(origin, typing.TypeAliasType):
+ for param in origin.__type_params__:
+ # there's no principled reason not to support these, they're just
+ # annoying to implement.
+ if isinstance(param, typing.TypeVarTuple):
+ raise HypothesisException(
+ f"Hypothesis does not yet support resolution for TypeVarTuple "
+ f"{param} (in origin: {origin!r}). Please open an issue if "
+ "you would like to see support for this."
+ )
+ if isinstance(param, typing.ParamSpec):
+ raise HypothesisException(
+ f"Hypothesis does not yet support resolution for ParamSpec "
+ f"{param} (in origin: {origin!r}). Please open an issue if you "
+ "would like to see support for this."
+ )
+ # this zip is non-strict to allow for e.g.
+ # `type A[T1, T2] = list[T1]; st.from_type(A[int]).example()`,
+ # which leaves T2 free but is still acceptable as it never references
+ # it.
+ #
+ # We disallow referencing a free / unbound type var by erroring
+ # elsewhere in this function.
+ typevars |= dict(zip(origin.__type_params__, concrete_args, strict=False))
+ return _evaluate_type_alias_type(origin.__value__, typevars=typevars)
+
+ return origin[concrete_args]
+
+
+def evaluate_type_alias_type(thing): # pragma: no cover # covered on 3.12+
+ # this function takes a GenericAlias whose origin is a TypeAliasType,
+ # which corresponds to `type A[T] = list[T]; thing = A[int]`, and returns
+ # the fully-instantiated underlying type.
+ assert isinstance(thing, GenericAlias)
+ assert is_a_type_alias_type(get_origin(thing))
+ return _evaluate_type_alias_type(thing, typevars={})
+
+
def is_a_type_alias_type(thing): # pragma: no cover # covered by 3.12+ tests
# TypeAliasType is new in python 3.12, through the type statement. If we're
# before python 3.12 then this can't possibly by a TypeAliasType.
diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py
index af13b6ffa0e..1b8e5a60276 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, 148, 11)
+__version_info__ = (6, 148, 12)
__version__ = ".".join(map(str, __version_info__))
diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make
index ed161e27502..9e7117c2ebf 100644
--- a/contrib/python/hypothesis/py3/ya.make
+++ b/contrib/python/hypothesis/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(6.148.11)
+VERSION(6.148.12)
LICENSE(MPL-2.0)