diff --git a/hypothesis-python/src/hypothesis/extra/array_api.py b/hypothesis-python/src/hypothesis/extra/array_api.py index d9c0ceec62..7a33a260f3 100644 --- a/hypothesis-python/src/hypothesis/extra/array_api.py +++ b/hypothesis-python/src/hypothesis/extra/array_api.py @@ -60,6 +60,9 @@ from hypothesis.strategies._internal.strategies import check_strategy from hypothesis.strategies._internal.utils import defines_strategy +if sys.version_info[:2] < (3, 8): + raise RuntimeError("The Array API standard requires Python 3.8 or later") + __all__ = [ "make_strategies_namespace", ] @@ -902,7 +905,7 @@ def make_strategies_namespace( check_argument( isinstance(xp.__array_api_version__, str) and xp.__array_api_version__ in RELEASED_VERSIONS, - f"{xp.__array_api_version__=}, but xp.__array_api_version__ must " + f"xp.__array_api_version__={xp.__array_api_version__!r}, but it must " f"be a valid version string {RELEASED_VERSIONS}. {not_available_msg}", ) api_version = xp.__array_api_version__ @@ -910,8 +913,8 @@ def make_strategies_namespace( else: check_argument( isinstance(api_version, str) and api_version in NOMINAL_VERSIONS, - f"{api_version=}, but api_version must be None, or a valid version " - f"string {RELEASED_VERSIONS}. {not_available_msg}", + f"api_version={api_version!r}, but it must be None, or a valid version " + f"string in {RELEASED_VERSIONS}. {not_available_msg}", ) inferred_version = False try: diff --git a/hypothesis-python/tests/cover/test_validation.py b/hypothesis-python/tests/cover/test_validation.py index c7c57573ce..ffc52e4678 100644 --- a/hypothesis-python/tests/cover/test_validation.py +++ b/hypothesis-python/tests/cover/test_validation.py @@ -9,6 +9,7 @@ # obtain one at https://mozilla.org/MPL/2.0/. import functools +import sys import pytest @@ -274,3 +275,13 @@ def test_check_strategy_might_suggest_sampled_from(): with pytest.raises(InvalidArgument, match="such as st.sampled_from"): check_strategy_((1, 2, 3)) check_strategy_(integers(), "passes for our custom coverage check") + + +@pytest.mark.skipif(sys.version_info[:2] >= (3, 8), reason="only on 3.7") +def test_explicit_error_from_array_api_before_py38(): + with pytest.raises( + RuntimeError, match=r"The Array API standard requires Python 3\.8 or later" + ): + from hypothesis.extra import array_api + + assert array_api # avoid unused-name lint error