diff options
| author | robot-piglet <[email protected]> | 2026-01-28 18:44:42 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2026-01-28 18:57:45 +0300 |
| commit | 05e202f574068972607e586c109c4ec188d83db6 (patch) | |
| tree | be5eb9071cd88b2437ceb635181e876be6b12d54 /contrib/python/hypothesis | |
| parent | bba0302b38f4f1cc9b0aba87783c7d833883b18f (diff) | |
Intermediate changes
commit_hash:299e2721e8f5b0e3b5c0075b45894e0c9d963b02
Diffstat (limited to 'contrib/python/hypothesis')
14 files changed, 103 insertions, 79 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA index d35d0315bd9..e53518c5500 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.150.1 +Version: 6.150.2 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/database.py b/contrib/python/hypothesis/py3/hypothesis/database.py index 68568675f32..4fbddd29021 100644 --- a/contrib/python/hypothesis/py3/hypothesis/database.py +++ b/contrib/python/hypothesis/py3/hypothesis/database.py @@ -76,7 +76,9 @@ def _usable_dir(path: StrPathT) -> bool: # Loop terminates because the root dir ('/' on unix) always exists. path = path.parent return path.is_dir() and os.access(path, os.R_OK | os.W_OK | os.X_OK) - except PermissionError: + except PermissionError: # pragma: no cover + # path.exists() returns False on 3.14+ instead of raising. See + # https://docs.python.org/3.14/library/pathlib.html#querying-file-type-and-status return False @@ -132,18 +134,36 @@ class _EDMeta(abc.ABCMeta): # This code only runs if Sphinx has already been imported; and it would live in our # docs/conf.py except that we would also like it to work for anyone documenting # downstream ExampleDatabase subclasses too. -if "sphinx" in sys.modules: +# +# We avoid type-checking this block due to this combination facts: +# * our check-types-api CI job runs under 3.14 +# * tools.txt therefore pins to a newer version of sphinx which uses 3.12+ `type` +# syntax +# * in test_mypy.py, mypy sees this block, sees sphinx is installed, tries parsing +# sphinx code, and errors +# +# Putting `and not TYPE_CHECKING` here is just a convenience for our testing setup +# (because we don't split mypy tests by running CI version, eg), not for runtime +# behavior. +if "sphinx" in sys.modules and not TYPE_CHECKING: # pragma: no cover try: import sphinx.ext.autodoc signature = "hypothesis.database._EDMeta.__call__" + + # _METACLASS_CALL_BLACKLIST moved in newer sphinx versions + try: + import sphinx.ext.autodoc._dynamic._signatures as _module + except ImportError: + _module = sphinx.ext.autodoc + # _METACLASS_CALL_BLACKLIST is a frozenset in later sphinx versions - if isinstance(sphinx.ext.autodoc._METACLASS_CALL_BLACKLIST, frozenset): - sphinx.ext.autodoc._METACLASS_CALL_BLACKLIST = ( - sphinx.ext.autodoc._METACLASS_CALL_BLACKLIST | {signature} - ) + if isinstance(_module._METACLASS_CALL_BLACKLIST, frozenset): + _module._METACLASS_CALL_BLACKLIST = _module._METACLASS_CALL_BLACKLIST | { + signature + } else: - sphinx.ext.autodoc._METACLASS_CALL_BLACKLIST.append(signature) + _module._METACLASS_CALL_BLACKLIST.append(signature) except Exception: pass diff --git a/contrib/python/hypothesis/py3/hypothesis/entry_points.py b/contrib/python/hypothesis/py3/hypothesis/entry_points.py index 4a68af7c436..98933265c27 100644 --- a/contrib/python/hypothesis/py3/hypothesis/entry_points.py +++ b/contrib/python/hypothesis/py3/hypothesis/entry_points.py @@ -17,23 +17,15 @@ your package. import importlib.metadata import os -from collections.abc import Generator, Sequence -from importlib.metadata import EntryPoint - - -def get_entry_points() -> Generator[EntryPoint, None, None]: - try: - eps: Sequence[EntryPoint] = importlib.metadata.entry_points(group="hypothesis") - except TypeError: # pragma: no cover - # Load-time selection requires Python >= 3.10. See also - # https://importlib-metadata.readthedocs.io/en/latest/using.html - eps = importlib.metadata.entry_points().get("hypothesis", []) - yield from eps def run() -> None: - if not os.environ.get("HYPOTHESIS_NO_PLUGINS"): - for entry in get_entry_points(): # pragma: no cover - hook = entry.load() - if callable(hook): - hook() + if os.environ.get("HYPOTHESIS_NO_PLUGINS"): + return + + for entry in importlib.metadata.entry_points( + group="hypothesis" + ): # pragma: no cover + hook = entry.load() + if callable(hook): + hook() diff --git a/contrib/python/hypothesis/py3/hypothesis/extra/_array_helpers.py b/contrib/python/hypothesis/py3/hypothesis/extra/_array_helpers.py index c688bc55089..802f571f24d 100644 --- a/contrib/python/hypothesis/py3/hypothesis/extra/_array_helpers.py +++ b/contrib/python/hypothesis/py3/hypothesis/extra/_array_helpers.py @@ -134,7 +134,8 @@ def valid_tuple_axes( min_size: int = 0, max_size: int | None = None, ) -> st.SearchStrategy[tuple[int, ...]]: - """All tuples will have a length >= ``min_size`` and <= ``max_size``. The default + """ + All tuples will have a length >= ``min_size`` and <= ``max_size``. The default value for ``max_size`` is ``ndim``. Examples from this strategy shrink towards an empty tuple, which render most @@ -153,7 +154,6 @@ def valid_tuple_axes( .. code-block:: python any_axis_strategy = none() | integers(-ndim, ndim - 1) | valid_tuple_axes(ndim) - """ check_type(int, ndim, "ndim") check_type(int, min_size, "min_size") @@ -364,7 +364,8 @@ def mutually_broadcastable_shapes( min_side: int = 1, max_side: int | None = None, ) -> st.SearchStrategy[BroadcastableShapes]: - """Return a strategy for a specified number of shapes N that are + """ + Return a strategy for a specified number of shapes N that are mutually-broadcastable with one another and with the provided base shape. * ``num_shapes`` is the number of mutually broadcast-compatible shapes to generate. @@ -397,7 +398,6 @@ def mutually_broadcastable_shapes( BroadcastableShapes(input_shapes=((), (), ()), result_shape=()) BroadcastableShapes(input_shapes=((3,), (), (3,)), result_shape=(3,)) BroadcastableShapes(input_shapes=((1, 2, 3), (3,), ()), result_shape=(1, 2, 3)) - """ arg_msg = "Pass either the `num_shapes` or the `signature` argument, but not both." if num_shapes is not not_set: diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/compat.py b/contrib/python/hypothesis/py3/hypothesis/internal/compat.py index 0c82a53e301..23ccc428152 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/compat.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/compat.py @@ -27,10 +27,10 @@ from typing import ( get_args, ) -try: - BaseExceptionGroup = BaseExceptionGroup - ExceptionGroup = ExceptionGroup # pragma: no cover -except NameError: +if sys.version_info >= (3, 11): + BaseExceptionGroup = BaseExceptionGroup # noqa: F821 + ExceptionGroup = ExceptionGroup # noqa: F821 +else: # pragma: no cover from exceptiongroup import ( BaseExceptionGroup as BaseExceptionGroup, ExceptionGroup as ExceptionGroup, @@ -47,7 +47,7 @@ else: # In order to use NotRequired, we need the version of TypedDict included in Python 3.11+. if sys.version_info[:2] >= (3, 11): from typing import NotRequired as NotRequired, TypedDict as TypedDict - else: + else: # pragma: no cover try: from typing_extensions import ( NotRequired as NotRequired, @@ -65,7 +65,7 @@ else: from typing import ( override as override, ) - except ImportError: + except ImportError: # pragma: no cover try: from typing_extensions import ( override as override, @@ -83,7 +83,7 @@ FREE_THREADED_CPYTHON = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) def add_note(exc, note): try: exc.add_note(note) - except AttributeError: + except AttributeError: # pragma: no cover if not hasattr(exc, "__notes__"): try: exc.__notes__ = [] @@ -251,6 +251,31 @@ def bad_django_TestCase(runner: Optional["ConjectureRunner"]) -> bool: # see issue #3812 if sys.version_info[:2] < (3, 12): + def _asdict_inner(obj, dict_factory): + if dataclasses._is_dataclass_instance(obj): + return dict_factory( + (f.name, _asdict_inner(getattr(obj, f.name), dict_factory)) + for f in dataclasses.fields(obj) + ) + elif isinstance(obj, tuple) and hasattr(obj, "_fields"): + return type(obj)(*[_asdict_inner(v, dict_factory) for v in obj]) + elif isinstance(obj, (list, tuple)): + return type(obj)(_asdict_inner(v, dict_factory) for v in obj) + elif isinstance(obj, dict): + if hasattr(type(obj), "default_factory"): + result = type(obj)(obj.default_factory) + for k, v in obj.items(): + result[_asdict_inner(k, dict_factory)] = _asdict_inner( + v, dict_factory + ) + return result + return type(obj)( + (_asdict_inner(k, dict_factory), _asdict_inner(v, dict_factory)) + for k, v in obj.items() + ) + else: + return copy.deepcopy(obj) + def dataclass_asdict(obj, *, dict_factory=dict): """ A vendored variant of dataclasses.asdict. Includes the bugfix for @@ -267,30 +292,6 @@ else: # pragma: no cover dataclass_asdict = dataclasses.asdict -def _asdict_inner(obj, dict_factory): - if dataclasses._is_dataclass_instance(obj): - return dict_factory( - (f.name, _asdict_inner(getattr(obj, f.name), dict_factory)) - for f in dataclasses.fields(obj) - ) - elif isinstance(obj, tuple) and hasattr(obj, "_fields"): - return type(obj)(*[_asdict_inner(v, dict_factory) for v in obj]) - elif isinstance(obj, (list, tuple)): - return type(obj)(_asdict_inner(v, dict_factory) for v in obj) - elif isinstance(obj, dict): - if hasattr(type(obj), "default_factory"): - result = type(obj)(obj.default_factory) - for k, v in obj.items(): - result[_asdict_inner(k, dict_factory)] = _asdict_inner(v, dict_factory) - return result - return type(obj)( - (_asdict_inner(k, dict_factory), _asdict_inner(v, dict_factory)) - for k, v in obj.items() - ) - else: - return copy.deepcopy(obj) - - if sys.version_info[:2] < (3, 13): # batched was added in 3.12, strict flag in 3.13 # copied from 3.13 docs reference implementation diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/provider_conformance.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/provider_conformance.py index 558bb686425..55ced851b5c 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/provider_conformance.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/provider_conformance.py @@ -44,7 +44,8 @@ def build_intervals(intervals: list[int]) -> list[tuple[int, int]]: if len(intervals) % 2: intervals = intervals[:-1] intervals.sort() - return list(batched(intervals, 2, strict=True)) + # help mypy infer tuple[int, ...] -> tuple[int, int] + return list(batched(intervals, 2, strict=True)) # type: ignore def interval_lists( diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py b/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py index 0082eb2d88e..63477860bf5 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py @@ -244,7 +244,7 @@ def get_seeder_and_restorer( def deterministic_PRNG(seed: int = 0) -> Generator[None, None, None]: """Context manager that handles random.seed without polluting global state. - See issue #1255 and PR #1295 for details and motivation - in short, + See issue #1266 and PR #1295 for details and motivation - in short, leaving the global pseudo-random number generator (PRNG) seeded is a very bad idea in principle, and breaks all kinds of independence assumptions in practice. diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py b/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py index 155e67e74a9..cf1f2f4f5d4 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py @@ -26,6 +26,7 @@ import ast import inspect import math import operator +import sys from collections.abc import Callable, Collection from decimal import Decimal from fractions import Fraction @@ -37,10 +38,9 @@ from hypothesis.internal.floats import next_down, next_up from hypothesis.internal.lambda_sources import lambda_description from hypothesis.internal.reflection import get_pretty_function_description -try: - # new in 3.14 - from functools import Placeholder # type: ignore -except ImportError: +if sys.version_info[:2] >= (3, 14): + from functools import Placeholder +else: # pragma: no cover Placeholder = object() Ex = TypeVar("Ex") diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/lambda_sources.py b/contrib/python/hypothesis/py3/hypothesis/internal/lambda_sources.py index 596b4c88106..0803c3010fb 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/lambda_sources.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/lambda_sources.py @@ -301,7 +301,7 @@ def _lambda_code_matches_node(f, node): return _function_key(f) == _function_key(compiled) -def _check_unknown_perfectly_aligned_lambda(candidate): +def _check_unknown_perfectly_aligned_lambda(candidate): # pragma: no cover # This is a monkeypatch point for our self-tests, to make unknown # lambdas raise. pass diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/reflection.py b/contrib/python/hypothesis/py3/hypothesis/internal/reflection.py index 87bf67a3e74..f462b10fcf1 100644 --- a/contrib/python/hypothesis/py3/hypothesis/internal/reflection.py +++ b/contrib/python/hypothesis/py3/hypothesis/internal/reflection.py @@ -116,7 +116,7 @@ def function_digest(function: Any) -> bytes: return hasher.digest() -def check_signature(sig: Signature) -> None: +def check_signature(sig: Signature) -> None: # pragma: no cover # 3.10 only # Backport from Python 3.11; see https://github.com/python/cpython/pull/92065 for p in sig.parameters.values(): if iskeyword(p.name) and p.kind is not p.POSITIONAL_ONLY: diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py index a9fbc392a9c..1f56b38f233 100644 --- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py +++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py @@ -1067,6 +1067,7 @@ class BuildsStrategy(SearchStrategy[Ex]): with context.track_arg_label(k) as arg_label: kwargs[k] = data.draw(v) arg_labels |= arg_label + try: obj = self.target(*args, **kwargs) except TypeError as err: @@ -2495,6 +2496,7 @@ def register_type_strategy( ) if ( "pydantic.generics" in sys.modules + and isinstance(custom_type, type) and issubclass(custom_type, sys.modules["pydantic.generics"].GenericModel) and not re.search(r"[A-Za-z_]+\[.+\]", repr(custom_type)) and callable(strategy) diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py index dae1691d151..84d73a2d203 100644 --- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py +++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py @@ -104,7 +104,7 @@ try: except AttributeError: # pragma: no cover pass # Is missing for `python<3.10` try: - TypeGuardTypes += (typing.TypeIs,) # type: ignore + TypeGuardTypes += (typing.TypeIs,) except AttributeError: # pragma: no cover pass # Is missing for `python<3.13` try: @@ -115,7 +115,7 @@ except AttributeError: # pragma: no cover RequiredTypes: tuple = () try: - RequiredTypes += (typing.Required,) # type: ignore + RequiredTypes += (typing.Required,) except AttributeError: # pragma: no cover pass # Is missing for `python<3.11` try: @@ -126,7 +126,7 @@ except AttributeError: # pragma: no cover NotRequiredTypes: tuple = () try: - NotRequiredTypes += (typing.NotRequired,) # type: ignore + NotRequiredTypes += (typing.NotRequired,) except AttributeError: # pragma: no cover pass # Is missing for `python<3.11` try: @@ -137,7 +137,7 @@ except AttributeError: # pragma: no cover ReadOnlyTypes: tuple = () try: - ReadOnlyTypes += (typing.ReadOnly,) # type: ignore + ReadOnlyTypes += (typing.ReadOnly,) except AttributeError: # pragma: no cover pass # Is missing for `python<3.13` try: @@ -148,7 +148,7 @@ except AttributeError: # pragma: no cover LiteralStringTypes: tuple = () try: - LiteralStringTypes += (typing.LiteralString,) # type: ignore + LiteralStringTypes += (typing.LiteralString,) except AttributeError: # pragma: no cover pass # Is missing for `python<3.11` try: @@ -202,7 +202,7 @@ for name in ( ): try: NON_RUNTIME_TYPES += (getattr(typing, name),) - except AttributeError: + except AttributeError: # pragma: no cover pass try: NON_RUNTIME_TYPES += (getattr(typing_extensions, name),) @@ -717,8 +717,13 @@ utc_offsets = st.builds( # exposed for it, and NotImplemented itself is typed as Any so that it can be # returned without being listed in a function signature: # https://github.com/python/mypy/issues/6710#issuecomment-485580032 +if sys.version_info < (3, 12): + _RegistryKeyT: typing.TypeAlias = type +else: # pragma: no cover + _RegistryKeyT: typing.TypeAlias = type | typing.TypeAliasType + _global_type_lookup: dict[ - type, st.SearchStrategy | typing.Callable[[type], st.SearchStrategy] + _RegistryKeyT, st.SearchStrategy | typing.Callable[[type], st.SearchStrategy] ] = { type(None): st.none(), bool: st.booleans(), @@ -976,8 +981,11 @@ def resolve_Tuple(thing): elem_types = getattr(thing, "__args__", None) or () if len(elem_types) == 2 and elem_types[-1] is Ellipsis: return st.lists(st.from_type(elem_types[0])).map(tuple) - elif len(elem_types) == 1 and elem_types[0] == (): - return st.tuples() # Empty tuple; see issue #1583 + elif len(elem_types) == 1 and elem_types[0] == (): # pragma: no cover + # Empty tuple; see issue #1583. + # Only possible on 3.10. `from typing import Tuple; Tuple[()].__args__` + # is ((),) on 3.10, and () on 3.11+. + return st.tuples() return st.tuples(*map(st.from_type, elem_types)) diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py index 7b87895ce34..f704b19fbd6 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, 150, 1) +__version_info__ = (6, 150, 2) __version__ = ".".join(map(str, __version_info__)) diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make index b003a5080ff..e3b2832f6ba 100644 --- a/contrib/python/hypothesis/py3/ya.make +++ b/contrib/python/hypothesis/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(6.150.1) +VERSION(6.150.2) LICENSE(MPL-2.0) |
