aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2023-12-09 02:21:24 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2023-12-09 02:39:10 +0300
commitc1d40b98e1b0bfa1c6e838bc5d7d7e4f1820dede (patch)
treeb2b08f3c123dc0452b400935c4fb0dc882257323 /contrib
parent89c24615f58622ebf40a727d10506d7217b7faaf (diff)
downloadydb-c1d40b98e1b0bfa1c6e838bc5d7d7e4f1820dede.tar.gz
Intermediate changes
Diffstat (limited to 'contrib')
-rw-r--r--contrib/python/hypothesis/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/_settings.py3
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/extra/lark.py21
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/datatree.py4
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/dfa/lstar.py10
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py10
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/conjecture/shrinker.py30
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/internal/filtering.py10
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py18
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/strategies/_internal/random.py6
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py80
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/vendor/pretty.py13
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt4
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/version.py2
-rw-r--r--contrib/python/hypothesis/py3/ya.make2
15 files changed, 142 insertions, 73 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA
index 80eb231761..d1b6f76c1d 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.88.4
+Version: 6.89.0
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/_settings.py b/contrib/python/hypothesis/py3/hypothesis/_settings.py
index 4751bb8086..b11ffc54a4 100644
--- a/contrib/python/hypothesis/py3/hypothesis/_settings.py
+++ b/contrib/python/hypothesis/py3/hypothesis/_settings.py
@@ -345,8 +345,7 @@ class settings(metaclass=settingsMeta):
@contextlib.contextmanager
def local_settings(s):
- default_context_manager = default_variable.with_value(s)
- with default_context_manager:
+ with default_variable.with_value(s):
yield s
diff --git a/contrib/python/hypothesis/py3/hypothesis/extra/lark.py b/contrib/python/hypothesis/py3/hypothesis/extra/lark.py
index 6320115661..9bab2c65ce 100644
--- a/contrib/python/hypothesis/py3/hypothesis/extra/lark.py
+++ b/contrib/python/hypothesis/py3/hypothesis/extra/lark.py
@@ -27,7 +27,6 @@ your own at all.
from inspect import signature
from typing import Dict, Optional
-import attr
import lark
from lark.grammar import NonTerminal, Terminal
@@ -40,20 +39,6 @@ from hypothesis.strategies._internal.utils import cacheable, defines_strategy
__all__ = ["from_lark"]
-@attr.s()
-class DrawState:
- """Tracks state of a single draw from a lark grammar.
-
- Currently just wraps a list of tokens that will be emitted at the
- end, but as we support more sophisticated parsers this will need
- to track more state for e.g. indentation level.
- """
-
- # The text output so far as a list of string tokens resulting from
- # each draw to a non-terminal.
- result = attr.ib(default=attr.Factory(list))
-
-
def get_terminal_names(terminals, rules, ignore_names):
"""Get names of all terminals in the grammar.
@@ -138,10 +123,10 @@ class LarkStrategy(st.SearchStrategy):
self.__rule_labels = {}
def do_draw(self, data):
- state = DrawState()
+ state = []
start = data.draw(self.start)
self.draw_symbol(data, start, state)
- return "".join(state.result)
+ return "".join(state)
def rule_label(self, name):
try:
@@ -162,7 +147,7 @@ class LarkStrategy(st.SearchStrategy):
'names-to-strategies, such as `{%r: st.just("")}`'
% (symbol.name, symbol.name)
) from None
- draw_state.result.append(data.draw(strategy))
+ draw_state.append(data.draw(strategy))
else:
assert isinstance(symbol, NonTerminal)
data.start_example(self.rule_label(symbol.name))
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/datatree.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/datatree.py
index b39666eec1..d82ed3ca67 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/datatree.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/datatree.py
@@ -88,8 +88,8 @@ class TreeNode:
# with the ``n_bits`` argument going in ``bit_lengths`` and the
# values seen in ``values``. These should always have the same
# length.
- bit_lengths = attr.ib(default=attr.Factory(IntList))
- values = attr.ib(default=attr.Factory(IntList))
+ bit_lengths = attr.ib(factory=IntList)
+ values = attr.ib(factory=IntList)
# The indices of of the calls to ``draw_bits`` that we have stored
# where ``forced`` is not None. Stored as None if no indices
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/dfa/lstar.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/dfa/lstar.py
index 28e5ebb770..061cb03825 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/dfa/lstar.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/dfa/lstar.py
@@ -87,25 +87,25 @@ class DistinguishedState:
distinct from ones we have previously seen so far."""
# Index of this state in the learner's list of states
- index = attr.ib()
+ index: int = attr.ib()
# A string that witnesses this state (i.e. when starting from the origin
# and following this string you will end up in this state).
- label = attr.ib()
+ label: str = attr.ib()
# A boolean as to whether this is an accepting state.
- accepting = attr.ib()
+ accepting: bool = attr.ib()
# A list of experiments that it is necessary to run to determine whether
# a string is in this state. This is stored as a dict mapping experiments
# to their expected result. A string is only considered to lead to this
# state if ``all(learner.member(s + experiment) == result for experiment,
# result in self.experiments.items())``.
- experiments = attr.ib()
+ experiments: dict = attr.ib()
# A cache of transitions out of this state, mapping bytes to the states
# that they lead to.
- transitions = attr.ib(default=attr.Factory(dict))
+ transitions: dict = attr.ib(factory=dict)
class LStar:
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py
index 6c5fc76cc8..6944e127de 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/engine.py
@@ -51,10 +51,10 @@ BUFFER_SIZE = 8 * 1024
@attr.s
class HealthCheckState:
- valid_examples = attr.ib(default=0)
- invalid_examples = attr.ib(default=0)
- overrun_examples = attr.ib(default=0)
- draw_times = attr.ib(default=attr.Factory(list))
+ valid_examples: int = attr.ib(default=0)
+ invalid_examples: int = attr.ib(default=0)
+ overrun_examples: int = attr.ib(default=0)
+ draw_times: list = attr.ib(factory=list)
class ExitReason(Enum):
@@ -976,7 +976,7 @@ class ConjectureRunner:
self,
example,
predicate,
- allow_transition,
+ allow_transition=allow_transition,
explain=Phase.explain in self.settings.phases,
)
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/shrinker.py b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/shrinker.py
index 82ff4ab88d..69bec60940 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/shrinker.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/conjecture/shrinker.py
@@ -9,7 +9,7 @@
# obtain one at https://mozilla.org/MPL/2.0/.
from collections import defaultdict
-from typing import TYPE_CHECKING, Dict
+from typing import TYPE_CHECKING, Callable, Dict, Optional
import attr
@@ -20,6 +20,7 @@ from hypothesis.internal.conjecture.choicetree import (
random_selection_order,
)
from hypothesis.internal.conjecture.data import ConjectureData, ConjectureResult, Status
+from hypothesis.internal.conjecture.dfa import ConcreteDFA
from hypothesis.internal.conjecture.floats import (
DRAW_FLOAT_LABEL,
float_to_lex,
@@ -261,7 +262,15 @@ class Shrinker:
accept.__name__ = fn.__name__
return property(accept)
- def __init__(self, engine, initial, predicate, allow_transition, explain):
+ def __init__(
+ self,
+ engine: "ConjectureRunner",
+ initial: ConjectureData,
+ predicate: Optional[Callable[..., bool]],
+ *,
+ allow_transition: bool,
+ explain: bool,
+ ):
"""Create a shrinker for a particular engine, with a given starting
point and predicate. When shrink() is called it will attempt to find an
example for which predicate is True and which is strictly smaller than
@@ -271,17 +280,17 @@ class Shrinker:
takes ConjectureData objects.
"""
assert predicate is not None or allow_transition is not None
- self.engine: "ConjectureRunner" = engine
+ self.engine = engine
self.__predicate = predicate or (lambda data: True)
self.__allow_transition = allow_transition or (lambda source, destination: True)
- self.__derived_values = {}
+ self.__derived_values: dict = {}
self.__pending_shrink_explanation = None
self.initial_size = len(initial.buffer)
# We keep track of the current best example on the shrink_target
# attribute.
- self.shrink_target: ConjectureData = initial
+ self.shrink_target = initial
self.clear_change_tracking()
self.shrinks = 0
@@ -293,12 +302,11 @@ class Shrinker:
self.initial_calls = self.engine.call_count
self.calls_at_last_shrink = self.initial_calls
- self.passes_by_name = {}
- self.passes = []
+ self.passes_by_name: Dict[str, ShrinkPass] = {}
# Extra DFAs that may be installed. This is used solely for
# testing and learning purposes.
- self.extra_dfas = {}
+ self.extra_dfas: Dict[str, ConcreteDFA] = {}
self.should_explain = explain
@@ -324,9 +332,8 @@ class Shrinker:
p = ShrinkPass(
run_with_chooser=definition.run_with_chooser,
shrinker=self,
- index=len(self.passes),
+ index=len(self.passes_by_name),
)
- self.passes.append(p)
self.passes_by_name[p.name] = p
return p
@@ -473,7 +480,8 @@ class Shrinker:
self.debug("Useless passes:")
self.debug("")
for p in sorted(
- self.passes, key=lambda t: (-t.calls, t.deletions, t.shrinks)
+ self.passes_by_name.values(),
+ key=lambda t: (-t.calls, t.deletions, t.shrinks),
):
if p.calls == 0:
continue
diff --git a/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py b/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py
index 8f15ba9ecf..8af37e453b 100644
--- a/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py
+++ b/contrib/python/hypothesis/py3/hypothesis/internal/filtering.py
@@ -29,7 +29,7 @@ import operator
from decimal import Decimal
from fractions import Fraction
from functools import partial
-from typing import Any, Callable, Dict, NamedTuple, Optional, TypeVar
+from typing import Any, Callable, Collection, Dict, NamedTuple, Optional, TypeVar
from hypothesis.internal.compat import ceil, floor
from hypothesis.internal.floats import next_down, next_up
@@ -295,3 +295,11 @@ def get_float_predicate_bounds(predicate: Predicate) -> ConstructivePredicate:
kwargs = {k: v for k, v in kwargs.items() if k in {"min_value", "max_value"}}
return ConstructivePredicate(kwargs, predicate)
+
+
+def max_len(size: int, element: Collection) -> bool:
+ return len(element) <= size
+
+
+def min_len(size: int, element: Collection) -> bool:
+ return size <= len(element)
diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py
index e3d7808943..3624e7e239 100644
--- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py
+++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/core.py
@@ -1269,12 +1269,18 @@ def _from_type(thing: Type[Ex]) -> SearchStrategy[Ex]:
# Let registered extra modules handle their own recognized types first, before
# e.g. Unions are resolved
- if thing not in types._global_type_lookup:
- for module, resolver in types._global_extra_lookup.items():
- if module in sys.modules:
- strat = resolver(thing)
- if strat is not None:
- return strat
+ try:
+ known = thing in types._global_type_lookup
+ except TypeError:
+ # thing is not always hashable!
+ pass
+ else:
+ if not known:
+ for module, resolver in types._global_extra_lookup.items():
+ if module in sys.modules:
+ strat = resolver(thing)
+ if strat is not None:
+ return strat
if not isinstance(thing, type):
if types.is_a_new_type(thing):
# Check if we have an explicitly registered strategy for this thing,
diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/random.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/random.py
index 882ed106e5..f7afd4d957 100644
--- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/random.py
+++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/random.py
@@ -11,7 +11,7 @@
import inspect
import math
from random import Random
-from typing import Dict
+from typing import Any, Dict
import attr
@@ -152,8 +152,8 @@ for r in RANDOM_METHODS:
@attr.s(slots=True)
class RandomState:
- next_states = attr.ib(default=attr.Factory(dict))
- state_id = attr.ib(default=None)
+ next_states: dict = attr.ib(factory=dict)
+ state_id: Any = attr.ib(default=None)
def state_for_seed(data, seed):
diff --git a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
index 9210f039d6..0a5fae4d9b 100644
--- a/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
+++ b/contrib/python/hypothesis/py3/hypothesis/strategies/_internal/types.py
@@ -19,20 +19,24 @@ import inspect
import io
import ipaddress
import numbers
+import operator
import os
import random
import re
import sys
import typing
import uuid
+import warnings
+from functools import partial
from pathlib import PurePath
from types import FunctionType
-from typing import get_args, get_origin
+from typing import TYPE_CHECKING, Any, Iterator, Tuple, get_args, get_origin
from hypothesis import strategies as st
-from hypothesis.errors import InvalidArgument, ResolutionFailed
+from hypothesis.errors import 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
from hypothesis.strategies._internal.datetime import zoneinfo # type: ignore
from hypothesis.strategies._internal.ipaddress import (
SPECIAL_IPv4_RANGES,
@@ -42,6 +46,9 @@ from hypothesis.strategies._internal.ipaddress import (
from hypothesis.strategies._internal.lazy import unwrap_strategies
from hypothesis.strategies._internal.strategies import OneOfStrategy
+if TYPE_CHECKING:
+ import annotated_types as at
+
GenericAlias: typing.Any
UnionType: typing.Any
try:
@@ -267,19 +274,64 @@ def is_annotated_type(thing):
)
-def find_annotated_strategy(annotated_type): # pragma: no cover
- flattened_meta = []
-
- all_args = (
- *getattr(annotated_type, "__args__", ()),
- *getattr(annotated_type, "__metadata__", ()),
- )
- for arg in all_args:
- if is_annotated_type(arg):
- flattened_meta.append(find_annotated_strategy(arg))
+def get_constraints_filter_map():
+ if at := sys.modules.get("annotated_types"): # pragma: no branch
+ return {
+ # Due to the order of operator.gt/ge/lt/le arguments, order is inversed:
+ at.Gt: lambda constraint: partial(operator.lt, constraint.gt),
+ at.Ge: lambda constraint: partial(operator.le, constraint.ge),
+ at.Lt: lambda constraint: partial(operator.gt, constraint.lt),
+ at.Le: lambda constraint: partial(operator.ge, constraint.le),
+ at.MinLen: lambda constraint: partial(min_len, constraint.min_length),
+ at.MaxLen: lambda constraint: partial(max_len, constraint.max_length),
+ at.Predicate: lambda constraint: constraint.func,
+ }
+ return {} # pragma: no cover
+
+
+def _get_constraints(args: Tuple[Any, ...]) -> Iterator["at.BaseMetadata"]:
+ if at := sys.modules.get("annotated_types"): # pragma: no branch
+ for arg in args:
+ if isinstance(arg, at.BaseMetadata):
+ yield arg
+ elif getattr(arg, "__is_annotated_types_grouped_metadata__", False):
+ yield from arg
+ elif isinstance(arg, slice) and arg.step in (1, None):
+ yield from at.Len(arg.start or 0, arg.stop)
+
+
+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
+ raise ResolutionFailed(
+ f"Failed to resolve strategy for the following Annotated type: {annotated_type}."
+ "Arguments to the Annotated type cannot be Annotated."
+ )
+ for arg in reversed(metadata):
if isinstance(arg, st.SearchStrategy):
- flattened_meta.append(arg)
- return flattened_meta[-1] if flattened_meta else None
+ return arg
+
+ filter_conditions = []
+ if "annotated_types" in sys.modules:
+ unsupported = []
+ for constraint in _get_constraints(metadata):
+ if convert := get_constraints_filter_map().get(type(constraint)):
+ filter_conditions.append(convert(constraint))
+ else:
+ unsupported.append(constraint)
+ if unsupported:
+ msg = f"Ignoring unsupported {', '.join(map(repr, unsupported))}"
+ warnings.warn(msg, HypothesisWarning, stacklevel=2)
+
+ base_strategy = st.from_type(annotated_type.__origin__)
+ for filter_condition in filter_conditions:
+ base_strategy = base_strategy.filter(filter_condition)
+
+ return base_strategy
def has_type_arguments(type_):
diff --git a/contrib/python/hypothesis/py3/hypothesis/vendor/pretty.py b/contrib/python/hypothesis/py3/hypothesis/vendor/pretty.py
index 5a1989182a..056f1795d3 100644
--- a/contrib/python/hypothesis/py3/hypothesis/vendor/pretty.py
+++ b/contrib/python/hypothesis/py3/hypothesis/vendor/pretty.py
@@ -832,6 +832,18 @@ def _repr_enum(obj, p, cycle):
p.text(f"{tname}.{obj.name}")
+class _ReprDots:
+ def __repr__(self) -> str:
+ return "..."
+
+
+def _repr_partial(obj, p, cycle):
+ args, kw = obj.args, obj.keywords
+ if cycle:
+ args, kw = (_ReprDots(),), {}
+ p.repr_call(pretty(type(obj)), (obj.func, *args), kw)
+
+
for_type_by_name("collections", "defaultdict", _defaultdict_pprint)
for_type_by_name("collections", "OrderedDict", _ordereddict_pprint)
for_type_by_name("ordereddict", "OrderedDict", _ordereddict_pprint)
@@ -839,3 +851,4 @@ for_type_by_name("collections", "deque", _deque_pprint)
for_type_by_name("collections", "Counter", _counter_pprint)
for_type_by_name("pandas.core.frame", "DataFrame", _repr_dataframe)
for_type_by_name("enum", "Enum", _repr_enum)
+for_type_by_name("functools", "partial", _repr_partial)
diff --git a/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt b/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt
index f8890db8fe..931aeb432b 100644
--- a/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt
+++ b/contrib/python/hypothesis/py3/hypothesis/vendor/tlds-alpha-by-domain.txt
@@ -1,4 +1,4 @@
-# Version 2023110200, Last Updated Thu Nov 2 07:07:01 2023 UTC
+# Version 2023111100, Last Updated Sat Nov 11 07:07:01 2023 UTC
AAA
AARP
ABB
@@ -642,7 +642,6 @@ KI
KIA
KIDS
KIM
-KINDER
KINDLE
KITCHEN
KIWI
@@ -984,7 +983,6 @@ RIL
RIO
RIP
RO
-ROCHER
ROCKS
RODEO
ROGERS
diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py
index 1177a5d565..24995e5689 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, 88, 4)
+__version_info__ = (6, 89, 0)
__version__ = ".".join(map(str, __version_info__))
diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make
index bd0d770d7a..2ff1945862 100644
--- a/contrib/python/hypothesis/py3/ya.make
+++ b/contrib/python/hypothesis/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(6.88.4)
+VERSION(6.89.0)
LICENSE(MPL-2.0)