Skip to content

Commit

Permalink
Explicit array-api error on Py37
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Nov 12, 2022
1 parent ab8bb72 commit b59c12c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hypothesis-python/src/hypothesis/extra/array_api.py
Expand Up @@ -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",
]
Expand Down Expand Up @@ -902,16 +905,16 @@ 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__
inferred_version = True
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:
Expand Down
11 changes: 11 additions & 0 deletions hypothesis-python/tests/cover/test_validation.py
Expand Up @@ -9,6 +9,7 @@
# obtain one at https://mozilla.org/MPL/2.0/.

import functools
import sys

import pytest

Expand Down Expand Up @@ -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

0 comments on commit b59c12c

Please sign in to comment.