Skip to content

Commit

Permalink
Merge pull request #4025 from HypothesisWorks/create-pull-request/patch
Browse files Browse the repository at this point in the history
Update pinned dependencies
  • Loading branch information
Zac-HD committed Jul 4, 2024
2 parents d8c1783 + f34ac1c commit dc99aa9
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 117 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ jobs:
- check-py313-cover
- check-py313-nocover
- check-py313-niche
# - check-py314-cover
# - check-py314-nocover
# - check-py314-niche
# - check-py313t-cover
# - check-py313t-nocover
# - check-py313t-niche
- check-py314-cover
- check-py314-nocover
- check-py314-niche
# - check-py314t-cover
# - check-py314t-nocover
# - check-py314t-niche
- check-quality
## Skip all the (inactive/old) Rust and Ruby tests pending fixes
# - lint-ruby
Expand Down
3 changes: 3 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RELEASE_TYPE: patch

This patch updates our autoformatting tools, improving our code style without any API changes.
2 changes: 1 addition & 1 deletion hypothesis-python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def local_file(name):
"pytest": ["pytest>=4.6"],
"dpcontracts": ["dpcontracts>=0.4"],
"redis": ["redis>=3.0.0"],
"crosshair": ["hypothesis-crosshair>=0.0.4", "crosshair-tool>=0.0.55"],
"crosshair": ["hypothesis-crosshair>=0.0.6", "crosshair-tool>=0.0.58"],
# zoneinfo is an odd one: every dependency is conditional, because they're
# only necessary on old versions of Python or Windows systems or emscripten.
"zoneinfo": [
Expand Down
10 changes: 8 additions & 2 deletions hypothesis-python/src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import math
import sys
import time
import traceback
import types
import unittest
import warnings
Expand Down Expand Up @@ -60,6 +61,7 @@
Flaky,
Found,
HypothesisDeprecationWarning,
HypothesisException,
HypothesisWarning,
InvalidArgument,
NoSuchExample,
Expand All @@ -86,9 +88,9 @@
from hypothesis.internal.escalation import (
InterestingOrigin,
current_pytest_item,
escalate_hypothesis_internal_error,
format_exception,
get_trimmed_traceback,
is_hypothesis_file,
)
from hypothesis.internal.healthcheck import fail_health_check
from hypothesis.internal.observability import (
Expand Down Expand Up @@ -1071,7 +1073,11 @@ def _execute_once_for_engine(self, data: ConjectureData) -> None:
except failure_exceptions_to_catch() as e:
# If the error was raised by Hypothesis-internal code, re-raise it
# as a fatal error instead of treating it as a test failure.
escalate_hypothesis_internal_error()
filepath = traceback.extract_tb(e.__traceback__)[-1][0]
if is_hypothesis_file(filepath) and not isinstance(
e, (HypothesisException, StopTest, UnsatisfiedAssumption)
):
raise

if data.frozen:
# This can happen if an error occurred in a finally
Expand Down
4 changes: 1 addition & 3 deletions hypothesis-python/src/hypothesis/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,9 @@ class DidNotReproduce(HypothesisException):
pass


class Found(Exception):
class Found(HypothesisException):
"""Signal that the example matches condition. Internal use only."""

hypothesis_internal_never_escalate = True


class RewindRecursive(Exception):
"""Signal that the type inference should be rewound due to recursive types. Internal use only."""
Expand Down
6 changes: 2 additions & 4 deletions hypothesis-python/src/hypothesis/internal/conjecture/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,8 @@ def ir_value_permitted(value, ir_type, kwargs):
if max_value is not None and value > max_value:
return False

if (max_value is None or min_value is None) and (
value - shrink_towards
).bit_length() >= 128:
return False
if max_value is None or min_value is None:
return (value - shrink_towards).bit_length() < 128

return True
elif ir_type == "float":
Expand Down
28 changes: 1 addition & 27 deletions hypothesis-python/src/hypothesis/internal/escalation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
from typing import Dict, NamedTuple, Optional, Type

import hypothesis
from hypothesis.errors import (
DeadlineExceeded,
HypothesisException,
StopTest,
UnsatisfiedAssumption,
_Trimmable,
)
from hypothesis.errors import _Trimmable
from hypothesis.internal.compat import BaseExceptionGroup
from hypothesis.utils.dynamicvariables import DynamicVariable

Expand Down Expand Up @@ -54,31 +48,11 @@ def accept(filepath):
return accept


PREVENT_ESCALATION = os.getenv("HYPOTHESIS_DO_NOT_ESCALATE") == "true"

FILE_CACHE: Dict[bytes, bool] = {}


is_hypothesis_file = belongs_to(hypothesis)

HYPOTHESIS_CONTROL_EXCEPTIONS = (DeadlineExceeded, StopTest, UnsatisfiedAssumption)


def escalate_hypothesis_internal_error():
if PREVENT_ESCALATION:
return

_, e, tb = sys.exc_info()

if getattr(e, "hypothesis_internal_never_escalate", False):
return

filepath = None if tb is None else traceback.extract_tb(tb)[-1][0]
if is_hypothesis_file(filepath) and not isinstance(
e, (HypothesisException, *HYPOTHESIS_CONTROL_EXCEPTIONS)
):
raise


def get_trimmed_traceback(exception=None):
"""Return the current traceback, minus any frames added by Hypothesis."""
Expand Down
17 changes: 10 additions & 7 deletions hypothesis-python/src/hypothesis/strategies/_internal/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,9 @@ def from_typing_type(thing):
for T in [*union_elems, elem_type]
):
mapping.pop(bytes, None)
mapping.pop(collections.abc.ByteString, None)
mapping.pop(typing.ByteString, None)
if sys.version_info[:2] <= (3, 13):
mapping.pop(collections.abc.ByteString, None)
mapping.pop(typing.ByteString, None)
elif (
(not mapping)
and isinstance(thing, typing.ForwardRef)
Expand Down Expand Up @@ -699,14 +700,16 @@ def _networks(bits):
# which includes this... but we don't actually ever want to build one.
_global_type_lookup[os._Environ] = st.just(os.environ)

if sys.version_info[:2] <= (3, 13):
# Note: while ByteString notionally also represents the bytearray and
# memoryview types, it is a subclass of Hashable and those types are not.
# We therefore only generate the bytes type. type-ignored due to deprecation.
_global_type_lookup[typing.ByteString] = st.binary() # type: ignore
_global_type_lookup[collections.abc.ByteString] = st.binary() # type: ignore


_global_type_lookup.update(
{
# Note: while ByteString notionally also represents the bytearray and
# memoryview types, it is a subclass of Hashable and those types are not.
# We therefore only generate the bytes type. type-ignored due to deprecation.
typing.ByteString: st.binary(), # type: ignore
collections.abc.ByteString: st.binary(), # type: ignore
# TODO: SupportsAbs and SupportsRound should be covariant, ie have functions.
typing.SupportsAbs: st.one_of(
st.booleans(),
Expand Down
27 changes: 0 additions & 27 deletions hypothesis-python/tests/cover/test_escalation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,6 @@
from hypothesis.internal.compat import BaseExceptionGroup


def test_does_not_escalate_errors_in_non_hypothesis_file():
try:
raise AssertionError
except AssertionError:
esc.escalate_hypothesis_internal_error()


def test_does_escalate_errors_in_hypothesis_file(monkeypatch):
monkeypatch.setattr(esc, "is_hypothesis_file", lambda x: True)

with pytest.raises(AssertionError):
try:
raise AssertionError
except AssertionError:
esc.escalate_hypothesis_internal_error()


def test_does_not_escalate_errors_in_hypothesis_file_if_disabled(monkeypatch):
monkeypatch.setattr(esc, "is_hypothesis_file", lambda x: True)
monkeypatch.setattr(esc, "PREVENT_ESCALATION", True)

try:
raise AssertionError
except AssertionError:
esc.escalate_hypothesis_internal_error()


def test_is_hypothesis_file_not_confused_by_prefix(monkeypatch):
# Errors in third-party extensions such as `hypothesis-trio` or
# `hypothesis-jsonschema` used to be incorrectly considered to be
Expand Down
11 changes: 9 additions & 2 deletions hypothesis-python/tests/cover/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
# We ignore TypeVar, because it is not a Generic type:
if isinstance(t, types.typing_root_type)
and t != typing.TypeVar
and (sys.version_info[:2] <= (3, 11) or t != typing.ByteString)
and (
sys.version_info[:2] <= (3, 11)
or t != getattr(typing, "ByteString", object())
)
),
key=str,
)
Expand Down Expand Up @@ -112,7 +115,10 @@ def test_typing_Type_Union(ex):
@pytest.mark.parametrize(
"typ",
[
collections.abc.ByteString,
pytest.param(
getattr(collections.abc, "ByteString", ...),
marks=pytest.mark.skipif(sys.version_info[:2] >= (3, 14), reason="removed"),
),
typing.Match,
typing.Pattern,
re.Match,
Expand Down Expand Up @@ -833,6 +839,7 @@ def test_bytestring_not_treated_as_generic_sequence(val):
assert isinstance(x, set)


@pytest.mark.skipif(sys.version_info[:2] >= (3, 14), reason="FIXME-py314")
@pytest.mark.parametrize(
"type_", [int, Real, object, typing.Union[int, str], typing.Union[Real, str]]
)
Expand Down
2 changes: 2 additions & 0 deletions hypothesis-python/tests/cover/test_sampled_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import collections
import enum
import sys

import pytest

Expand Down Expand Up @@ -196,6 +197,7 @@ class AnnotationsInsteadOfElements(enum.Enum):
a: "int"


@pytest.mark.skipif(sys.version_info[:2] >= (3, 14), reason="FIXME-py314")
def test_suggests_elements_instead_of_annotations():
with pytest.raises(InvalidArgument, match="Cannot sample.*annotations.*dataclass"):
check_can_generate_examples(st.sampled_from(AnnotationsInsteadOfElements))
Expand Down
6 changes: 4 additions & 2 deletions hypothesis-python/tests/cover/test_type_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import abc
import enum
import sys
from inspect import Parameter as P, Signature
from typing import Callable, Dict, Generic, List, Sequence, TypeVar, Union

Expand Down Expand Up @@ -73,6 +74,7 @@
continue


@pytest.mark.skipif(sys.version_info[:2] >= (3, 14), reason="FIXME-py314")
def test_generic_sequence_of_integers_may_be_lists_or_bytes():
strat = st.from_type(Sequence[int])
find_any(strat, lambda x: isinstance(x, bytes))
Expand Down Expand Up @@ -292,12 +294,12 @@ def test_generic_origin_empty():

def test_issue_2951_regression():
lines_strat = st.builds(Lines, lines=st.lists(st.text()))
prev_seq_int_repr = repr(st.from_type(Sequence[int]))
with temp_registered(Lines, lines_strat):
assert st.from_type(Lines) == lines_strat
# Now let's test that the strategy for ``Sequence[int]`` did not
# change just because we registered a strategy for ``Lines``:
expected = "one_of(binary(), lists(integers()))"
assert repr(st.from_type(Sequence[int])) == expected
assert repr(st.from_type(Sequence[int])) == prev_seq_int_repr


def test_issue_2951_regression_two_params():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@
settings,
strategies as st,
)
from hypothesis.internal import escalation as esc
from hypothesis.internal.conjecture.data import Status
from hypothesis.internal.conjecture.engine import ConjectureRunner


def setup_module(module):
esc.PREVENT_ESCALATION = True


def teardown_module(module):
esc.PREVENT_ESCALATION = False


@attr.s()
class Write:
value = attr.ib()
Expand Down
4 changes: 2 additions & 2 deletions requirements/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exceptiongroup==1.2.1 ; python_version < "3.11"
# pytest
execnet==2.1.1
# via pytest-xdist
fakeredis==2.23.2
fakeredis==2.23.3
# via -r requirements/coverage.in
iniconfig==2.0.0
# via pytest
Expand Down Expand Up @@ -78,7 +78,7 @@ pytz==2024.1
# pandas
pyyaml==6.0.1
# via libcst
redis==5.0.6
redis==5.0.7
# via fakeredis
six==1.16.0
# via python-dateutil
Expand Down
14 changes: 7 additions & 7 deletions requirements/fuzzing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ black==24.4.2
# hypothesis
blinker==1.8.2
# via flask
certifi==2024.6.2
certifi==2024.7.4
# via requests
charset-normalizer==3.3.2
# via requests
Expand Down Expand Up @@ -50,17 +50,17 @@ exceptiongroup==1.2.1 ; python_version < "3.11"
# pytest
execnet==2.1.1
# via pytest-xdist
fakeredis==2.23.2
fakeredis==2.23.3
# via -r requirements/coverage.in
flask==3.0.3
# via dash
hypofuzz==24.2.3
# via -r requirements/fuzzing.in
hypothesis[cli]==6.103.2
hypothesis[cli]==6.104.2
# via hypofuzz
idna==3.7
# via requests
importlib-metadata==7.2.1
importlib-metadata==8.0.0
# via dash
iniconfig==2.0.0
# via pytest
Expand Down Expand Up @@ -138,7 +138,7 @@ pytz==2024.1
# pandas
pyyaml==6.0.1
# via libcst
redis==5.0.6
redis==5.0.7
# via fakeredis
requests==2.32.3
# via
Expand All @@ -157,7 +157,7 @@ sortedcontainers==2.4.0
# fakeredis
# hypothesis
# hypothesis (hypothesis-python/setup.py)
tenacity==8.4.1
tenacity==8.4.2
# via plotly
tomli==2.0.1
# via
Expand All @@ -182,5 +182,5 @@ zipp==3.19.2
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
setuptools==70.1.0
setuptools==70.2.0
# via dash
Loading

0 comments on commit dc99aa9

Please sign in to comment.