Skip to content

Commit 0e5155d

Browse files
committed
Inferred api_version shares cache key with specified versions
1 parent bc4bcb6 commit 0e5155d

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

hypothesis-python/src/hypothesis/extra/array_api.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -886,13 +886,6 @@ def make_strategies_namespace(
886886
True
887887
888888
"""
889-
try:
890-
namespace = _args_to_xps[(xp, api_version)]
891-
except (KeyError, TypeError):
892-
pass
893-
else:
894-
return namespace
895-
896889
not_available_msg = (
897890
"If the standard version you want is not available, please ensure "
898891
"you're using the latest version of Hypothesis, then open an issue if "
@@ -930,6 +923,13 @@ def make_strategies_namespace(
930923
HypothesisWarning,
931924
)
932925

926+
try:
927+
namespace = _args_to_xps[(xp, api_version)]
928+
except (KeyError, TypeError):
929+
pass
930+
else:
931+
return namespace
932+
933933
@defines_strategy(force_reusable_values=True)
934934
def from_dtype(
935935
dtype: Union[DataType, str],
@@ -1076,7 +1076,7 @@ def complex_dtypes(
10761076

10771077
namespace = StrategiesNamespace(**kwargs)
10781078
try:
1079-
_args_to_xps[(xp, None if inferred_version else api_version)] = namespace
1079+
_args_to_xps[(xp, api_version)] = namespace
10801080
except TypeError:
10811081
pass
10821082

hypothesis-python/tests/array_api/test_strategies_namespace.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ def test_caching(api_version, monkeypatch):
5858
@pytest.mark.parametrize(
5959
"api_version1, api_version2", [(None, "2021.12"), ("2021.12", None)]
6060
)
61-
def test_inferred_namespace_is_cached_seperately(
62-
api_version1, api_version2, monkeypatch
63-
):
64-
"""Results from inferred versions do not share the same cache key as results
61+
def test_inferred_namespace_shares_cache(api_version1, api_version2, monkeypatch):
62+
"""Results from inferred versions share the same cache key as results
6563
from specified versions."""
6664
xp = HashableArrayModuleFactory()
6765
xp.__array_api_version__ = "2021.12"
@@ -73,8 +71,8 @@ def test_inferred_namespace_is_cached_seperately(
7371
assert len(array_api._args_to_xps) == 1
7472
xps2 = array_api.make_strategies_namespace(xp, api_version=api_version2)
7573
assert xps2.api_version == "2021.12" # sanity check
76-
assert len(array_api._args_to_xps) == 2
77-
assert xps2 is not xps1
74+
assert len(array_api._args_to_xps) == 1
75+
assert xps2 is xps1
7876

7977

8078
def test_complex_dtypes_raises_on_2021_12():

0 commit comments

Comments
 (0)