|
11 | 11 | import warnings |
12 | 12 | from collections.abc import Hashable |
13 | 13 | from typing import Any, Optional |
14 | | -from weakref import WeakKeyDictionary |
15 | 14 |
|
16 | 15 | from hypothesis.errors import HypothesisWarning |
17 | 16 | from hypothesis.internal.conjecture.data import ConjectureData |
@@ -46,15 +45,11 @@ def do_draw(self, data: ConjectureData) -> Any: |
46 | 45 |
|
47 | 46 | if other.base is not self.base: |
48 | 47 | # 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: |
58 | 53 | warnings.warn( |
59 | 54 | f"Different strategies are shared under {key=}. This" |
60 | 55 | " risks drawing values that are not valid examples for the strategy," |
|
0 commit comments