Skip to content

Commit

Permalink
Remove MissingExtras warning and associated tests/checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jobh committed Jun 4, 2023
1 parent b6a5a25 commit b2202bf
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 32 deletions.
4 changes: 0 additions & 4 deletions hypothesis-python/src/hypothesis/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,3 @@ def __init__(self, target):
class SmallSearchSpaceWarning(HypothesisWarning):
"""Indicates that an inferred strategy does not span the search space
in a meaningful way, for example by only creating default instances."""


class MissingExtraWarning(HypothesisWarning):
"""Indicates that an extra package should be installed to improve functionality."""
12 changes: 1 addition & 11 deletions hypothesis-python/src/hypothesis/strategies/_internal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
from hypothesis.control import cleanup, current_build_context, note
from hypothesis.errors import (
InvalidArgument,
MissingExtraWarning,
ResolutionFailed,
RewindRecursive,
SmallSearchSpaceWarning,
Expand Down Expand Up @@ -1218,16 +1217,7 @@ def from_type_guarded(thing):
try:
from hypothesis.extra.numpy import from_type_internal

return from_type_internal(thing) # pragma: no cover
except ImportError:
if getattr(thing, "__module__", None) == "numpy": # pragma: no cover
from_type_repr = repr_call(from_type, (thing,), {})
warnings.warn(
f"{from_type_repr} might be resolved by hypothesis.extra.numpy, "
"but that subpackage is not installed. Consider installing it, "
"or use st.register_type_strategy() to silence this warning.",
MissingExtraWarning,
)
return from_type_internal(thing)
except Exception: # pragma: no cover
pass
# Finally, try to build an instance by calling the type object. Unlike builds(),
Expand Down
17 changes: 0 additions & 17 deletions hypothesis-python/tests/cover/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from hypothesis import HealthCheck, assume, given, settings, strategies as st
from hypothesis.errors import (
InvalidArgument,
MissingExtraWarning,
ResolutionFailed,
SmallSearchSpaceWarning,
)
Expand Down Expand Up @@ -1031,19 +1030,3 @@ def f(x: int):
msg = "@no_type_check decorator prevented Hypothesis from inferring a strategy"
with pytest.raises(TypeError, match=msg):
st.builds(f).example()


@pytest.mark.skipif(
importlib.util.find_spec("numpy") is None,
reason="numpy is not available",
)
def test_numpy_type():
import numpy as np

try:
import hypothesis.extra.numpy # noqa: F401
except ImportError:
with pytest.warns((MissingExtraWarning, SmallSearchSpaceWarning)):
st.from_type(np.int8).example()
else:
st.from_type(np.int8).example()

0 comments on commit b2202bf

Please sign in to comment.