Skip to content

Commit bb9a9bf

Browse files
committed
Simplify, type fix
1 parent 2d099ca commit bb9a9bf

File tree

2 files changed

+6
-11
lines changed
  • hypothesis-python/src/hypothesis

2 files changed

+6
-11
lines changed

hypothesis-python/src/hypothesis/internal/conjecture/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def __init__(
706706
self._sampled_from_all_strategies_elements_message: Optional[
707707
tuple[str, object]
708708
] = None
709-
self._shared_strategy_draws: dict[Hashable, tuple[int, Any]] = {}
709+
self._shared_strategy_draws: dict[Hashable, tuple[Any, "SharedStrategy"]] = {}
710710
self._shared_data_strategy: Optional[DataObject] = None
711711
self._stateful_repr_parts: Optional[list[Any]] = None
712712
self.states_for_ids: Optional[dict[int, RandomState]] = None

hypothesis-python/src/hypothesis/strategies/_internal/shared.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import warnings
1212
from collections.abc import Hashable
1313
from typing import Any, Optional
14-
from weakref import WeakKeyDictionary
1514

1615
from hypothesis.errors import HypothesisWarning
1716
from hypothesis.internal.conjecture.data import ConjectureData
@@ -46,15 +45,11 @@ def do_draw(self, data: ConjectureData) -> Any:
4645

4746
if other.base is not self.base:
4847
# Check that the strategies shared under this key are equivalent,
49-
# approximated as having equal `repr`s.
50-
try:
51-
is_equivalent = self._equivalent_to[other]
52-
except (AttributeError, KeyError) as e:
53-
if isinstance(e, AttributeError):
54-
self._equivalent_to = WeakKeyDictionary()
55-
is_equivalent = repr(self.base) == repr(other.base)
56-
self._equivalent_to[other] = is_equivalent
57-
if not is_equivalent:
48+
# approximated as having equal `repr`s. False positives are ok,
49+
# false negatives (erroneous warnings) less so.
50+
if not hasattr(self, "_is_compatible"):
51+
self._is_compatible = repr(self.base) == repr(other.base)
52+
if not self._is_compatible:
5853
warnings.warn(
5954
f"Different strategies are shared under {key=}. This"
6055
" risks drawing values that are not valid examples for the strategy,"

0 commit comments

Comments
 (0)