aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/hypothesis/py3
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-03-08 12:14:09 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-03-08 12:22:31 +0300
commit9584fd808b5bbcd989348a67768064134e3341d9 (patch)
tree601ec8deabb8dcdca66d4123cd7a0dcf7d804243 /contrib/python/hypothesis/py3
parente8116f70daae60dcbf13132581dba893802ce3fe (diff)
downloadydb-9584fd808b5bbcd989348a67768064134e3341d9.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/hypothesis/py3')
-rw-r--r--contrib/python/hypothesis/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py11
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/stateful.py19
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py35
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/version.py2
-rw-r--r--contrib/python/hypothesis/py3/ya.make2
6 files changed, 53 insertions, 18 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA
index d883f6dec6..171a09eebb 100644
--- a/contrib/python/hypothesis/py3/.dist-info/METADATA
+++ b/contrib/python/hypothesis/py3/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: hypothesis
-Version: 6.98.9
+Version: 6.98.10
Summary: A library for property-based testing
Home-page: https://hypothesis.works
Author: David R. MacIver and Zac Hatfield-Dodds
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
index 0016f2fa1a..cdce1afacf 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/data.py
@@ -40,7 +40,7 @@ import attr
from hypothesis.errors import Frozen, InvalidArgument, StopTest
from hypothesis.internal.cache import LRUReusedCache
-from hypothesis.internal.compat import floor, int_from_bytes, int_to_bytes
+from hypothesis.internal.compat import add_note, floor, int_from_bytes, int_to_bytes
from hypothesis.internal.conjecture.floats import float_to_lex, lex_to_float
from hypothesis.internal.conjecture.junkdrawer import IntList, uniform
from hypothesis.internal.conjecture.utils import (
@@ -1748,14 +1748,17 @@ class ConjectureData:
try:
if not at_top_level:
return strategy.do_draw(self)
- else:
- assert start_time is not None
+ assert start_time is not None
+ key = observe_as or f"generate:unlabeled_{len(self.draw_times)}"
+ try:
strategy.validate()
try:
return strategy.do_draw(self)
finally:
- key = observe_as or f"generate:unlabeled_{len(self.draw_times)}"
self.draw_times[key] = time.perf_counter() - start_time
+ except Exception as err:
+ add_note(err, f"while generating {key[9:]!r} from {strategy!r}")
+ raise
finally:
self.stop_example()
diff --git a/contrib/python/hypothesis/py3/hypothesis/stateful.py b/contrib/python/hypothesis/py3/hypothesis/stateful.py
index bf7271fc4c..2ab7ef13d5 100644
--- a/contrib/python/hypothesis/py3/hypothesis/stateful.py
+++ b/contrib/python/hypothesis/py3/hypothesis/stateful.py
@@ -47,6 +47,7 @@ from hypothesis._settings import (
from hypothesis.control import _current_build_context, current_build_context
from hypothesis.core import TestFunc, given
from hypothesis.errors import InvalidArgument, InvalidDefinition
+from hypothesis.internal.compat import add_note
from hypothesis.internal.conjecture import utils as cu
from hypothesis.internal.healthcheck import fail_health_check
from hypothesis.internal.observability import TESTCASE_CALLBACKS
@@ -439,18 +440,16 @@ class Rule:
bundles = attr.ib(init=False)
def __attrs_post_init__(self):
- arguments = {}
+ self.arguments_strategies = {}
bundles = []
for k, v in sorted(self.arguments.items()):
assert not isinstance(v, BundleReferenceStrategy)
if isinstance(v, Bundle):
bundles.append(v)
consume = isinstance(v, BundleConsumer)
- arguments[k] = BundleReferenceStrategy(v.name, consume=consume)
- else:
- arguments[k] = v
+ v = BundleReferenceStrategy(v.name, consume=consume)
+ self.arguments_strategies[k] = v
self.bundles = tuple(bundles)
- self.arguments_strategy = st.fixed_dictionaries(arguments)
self_strategy = st.runner()
@@ -978,7 +977,15 @@ class RuleStrategy(SearchStrategy):
.filter(lambda r: feature_flags.is_enabled(r.function.__name__))
)
- return (rule, data.draw(rule.arguments_strategy))
+ arguments = {}
+ for k, strat in rule.arguments_strategies.items():
+ try:
+ arguments[k] = data.draw(strat)
+ except Exception as err:
+ rname = rule.function.__name__
+ add_note(err, f"while generating {k!r} from {strat!r} for rule {rname}")
+ raise
+ return (rule, arguments)
def is_valid(self, rule):
predicates = self.machine._observability_predicates
diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
index d91102cb50..7c4e584ee6 100644
--- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
+++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
@@ -37,6 +37,7 @@ from hypothesis.errors import HypothesisWarning, InvalidArgument, ResolutionFail
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
+from hypothesis.internal.reflection import get_pretty_function_description
from hypothesis.strategies._internal.datetime import zoneinfo # type: ignore
from hypothesis.strategies._internal.ipaddress import (
SPECIAL_IPv4_RANGES,
@@ -300,16 +301,40 @@ def _get_constraints(args: Tuple[Any, ...]) -> Iterator["at.BaseMetadata"]:
yield from at.Len(arg.start or 0, arg.stop)
+def _flat_annotated_repr_parts(annotated_type):
+ # Helper to get a good error message in find_annotated_strategy() below.
+ type_reps = [
+ get_pretty_function_description(a)
+ for a in annotated_type.__args__
+ if not isinstance(a, typing.TypeVar)
+ ]
+ metadata_reps = []
+ for m in getattr(annotated_type, "__metadata__", ()):
+ if is_annotated_type(m):
+ ts, ms = _flat_annotated_repr_parts(m)
+ type_reps.extend(ts)
+ metadata_reps.extend(ms)
+ else:
+ metadata_reps.append(get_pretty_function_description(m))
+ return type_reps, metadata_reps
+
+
def find_annotated_strategy(annotated_type):
metadata = getattr(annotated_type, "__metadata__", ())
if any(is_annotated_type(arg) for arg in metadata):
- # We are in the case where one of the metadata argument
- # is itself an annotated type. Although supported at runtime,
- # This shouldn't be allowed: we prefer to raise here
+ # Annotated[Annotated[T], ...] is perfectly acceptable, but it's all to easy
+ # to instead write Annotated[T1, Annotated[T2, ...]] - and nobody else checks
+ # for that at runtime. Once you add generics this can be seriously confusing,
+ # so we go to some trouble to give a helpful error message.
+ # For details: https://github.com/HypothesisWorks/hypothesis/issues/3891
+ ty_rep = repr(annotated_type).replace("typing.Annotated", "Annotated")
+ ts, ms = _flat_annotated_repr_parts(annotated_type)
+ bits = ", ".join([" | ".join(dict.fromkeys(ts or "?")), *dict.fromkeys(ms)])
raise ResolutionFailed(
- f"Failed to resolve strategy for the following Annotated type: {annotated_type}."
- "Arguments to the Annotated type cannot be Annotated."
+ f"`{ty_rep}` is invalid because nesting Annotated is only allowed for "
+ f"the first (type) argument, not for later (metadata) arguments. "
+ f"Did you mean `Annotated[{bits}]`?"
)
for arg in reversed(metadata):
if isinstance(arg, st.SearchStrategy):
diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py
index f54f8dc42f..ce617c47e9 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, 98, 9)
+__version_info__ = (6, 98, 10)
__version__ = ".".join(map(str, __version_info__))
diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make
index 89269430da..4c7de0c00e 100644
--- a/contrib/python/hypothesis/py3/ya.make
+++ b/contrib/python/hypothesis/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(6.98.9)
+VERSION(6.98.10)
LICENSE(MPL-2.0)