Skip to content

Commit

Permalink
Update dependencies + fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jul 4, 2024
1 parent d8c1783 commit 70897dc
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 106 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ 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-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
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
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
24 changes: 12 additions & 12 deletions requirements/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ build==1.2.1
# via pip-tools
cachetools==5.3.3
# via tox
certifi==2024.6.2
certifi==2024.7.4
# via requests
cffi==1.16.0
# via cryptography
Expand Down Expand Up @@ -91,13 +91,13 @@ idna==3.7
# requests
imagesize==1.4.1
# via sphinx
importlib-metadata==7.2.1
importlib-metadata==8.0.0
# via
# keyring
# twine
iniconfig==2.0.0
# via pytest
ipython==8.25.0
ipython==8.26.0
# via -r requirements/tools.in
isort==5.13.2
# via shed
Expand Down Expand Up @@ -141,7 +141,7 @@ more-itertools==10.3.0
# via
# jaraco-classes
# jaraco-functools
mypy==1.10.0
mypy==1.10.1
# via -r requirements/tools.in
mypy-extensions==1.0.0
# via
Expand Down Expand Up @@ -173,7 +173,7 @@ pexpect==4.9.0
# via ipython
pip-tools==7.4.1
# via -r requirements/tools.in
pkginfo==1.11.1
pkginfo==1.10.0
# via twine
platformdirs==4.2.2
# via
Expand Down Expand Up @@ -207,7 +207,7 @@ pyproject-hooks==1.1.0
# via
# build
# pip-tools
pyright==1.1.368
pyright==1.1.370
# via -r requirements/tools.in
pytest==8.2.2
# via -r requirements/tools.in
Expand Down Expand Up @@ -242,7 +242,7 @@ rich==13.7.1
# via
# pelican
# twine
ruff==0.4.10
ruff==0.5.0
# via -r requirements/tools.in
secretstorage==3.3.3
# via keyring
Expand Down Expand Up @@ -310,13 +310,13 @@ tomli==2.0.1
# pytest
# sphinx
# tox
tox==4.15.1
tox==4.16.0
# via -r requirements/tools.in
traitlets==5.14.3
# via
# ipython
# matplotlib-inline
twine==5.1.0
twine==5.1.1
# via -r requirements/tools.in
types-cffi==1.16.0.20240331
# via types-pyopenssl
Expand All @@ -330,7 +330,7 @@ types-pytz==2024.1.0.20240417
# via -r requirements/tools.in
types-redis==4.6.0.20240425
# via -r requirements/tools.in
types-setuptools==70.0.0.20240524
types-setuptools==70.2.0.20240704
# via types-cffi
typing-extensions==4.12.2
# via
Expand Down Expand Up @@ -358,7 +358,7 @@ zipp==3.19.2
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
pip==24.1
pip==24.1.1
# via pip-tools
setuptools==70.1.0
setuptools==70.2.0
# via pip-tools
Loading

0 comments on commit 70897dc

Please sign in to comment.