Skip to content

Commit

Permalink
Merge pull request #4119 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 authored Sep 29, 2024
2 parents 75650b9 + 2958a45 commit 3c1350d
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 21 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch fixes an internal error when the ``__context__``
attribute of a raised exception leads to a cycle (:issue:`4115`).
4 changes: 2 additions & 2 deletions hypothesis-python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def local_file(name):
"pytest": ["pytest>=4.6"],
"dpcontracts": ["dpcontracts>=0.4"],
"redis": ["redis>=3.0.0"],
"crosshair": ["hypothesis-crosshair>=0.0.14", "crosshair-tool>=0.0.71"],
"crosshair": ["hypothesis-crosshair>=0.0.14", "crosshair-tool>=0.0.72"],
# 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": [
"tzdata>=2024.1 ; sys_platform == 'win32' or sys_platform == 'emscripten'",
"tzdata>=2024.2 ; sys_platform == 'win32' or sys_platform == 'emscripten'",
"backports.zoneinfo>=0.2.1 ; python_version<'3.9'",
],
# We only support Django versions with upstream support - see
Expand Down
16 changes: 12 additions & 4 deletions hypothesis-python/src/hypothesis/internal/escalation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import sys
import textwrap
import traceback
from functools import partial
from inspect import getframeinfo
from pathlib import Path
from typing import Dict, NamedTuple, Optional, Type
from typing import Dict, NamedTuple, Optional, Tuple, Type

import hypothesis
from hypothesis.errors import _Trimmable
Expand Down Expand Up @@ -107,20 +108,27 @@ def __str__(self) -> str:
return f"{self.exc_type.__name__} at {self.filename}:{self.lineno}{ctx}{group}"

@classmethod
def from_exception(cls, exception: BaseException, /) -> "InterestingOrigin":
def from_exception(
cls, exception: BaseException, /, seen: Tuple[BaseException, ...] = ()
) -> "InterestingOrigin":
filename, lineno = None, None
if tb := get_trimmed_traceback(exception):
filename, lineno, *_ = traceback.extract_tb(tb)[-1]
seen = (*seen, exception)
make = partial(cls.from_exception, seen=seen)
context: "InterestingOrigin | tuple[()]" = ()
if exception.__context__ is not None and exception.__context__ not in seen:
context = make(exception.__context__)
return cls(
type(exception),
filename,
lineno,
# Note that if __cause__ is set it is always equal to __context__, explicitly
# to support introspection when debugging, so we can use that unconditionally.
cls.from_exception(exception.__context__) if exception.__context__ else (),
context,
# We distinguish exception groups by the inner exceptions, as for __context__
(
tuple(map(cls.from_exception, exception.exceptions))
tuple(make(exc) for exc in exception.exceptions if exc not in seen)
if isinstance(exception, BaseExceptionGroup)
else ()
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version 2024071300, Last Updated Sat Jul 13 07:07:01 2024 UTC
# Version 2024092800, Last Updated Sat Sep 28 07:07:01 2024 UTC
AAA
AARP
ABB
Expand Down Expand Up @@ -297,7 +297,6 @@ CY
CYMRU
CYOU
CZ
DABUR
DAD
DANCE
DATA
Expand Down
23 changes: 23 additions & 0 deletions hypothesis-python/tests/cover/test_escalation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,26 @@ def test_handles_groups():
assert "ExceptionGroup at " in str(origin)
assert "child exception" in str(origin)
assert "ValueError at " in str(origin)


def make_exceptions_with_cycles():
err = ValueError()
err.__context__ = err
yield err

err = TypeError()
err.__context__ = BaseExceptionGroup("msg", [err])
yield err

inner = LookupError()
err = BaseExceptionGroup("msg", [inner])
inner.__context__ = err
yield err

inner = OSError()
yield BaseExceptionGroup("msg", [inner, inner, inner])


@pytest.mark.parametrize("err", list(make_exceptions_with_cycles()))
def test_handles_cycles(err):
esc.InterestingOrigin.from_exception(err)
6 changes: 3 additions & 3 deletions requirements/coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exceptiongroup==1.2.2 ; python_version < "3.11"
# pytest
execnet==2.1.1
# via pytest-xdist
fakeredis==2.24.1
fakeredis==2.25.0
# via -r requirements/coverage.in
iniconfig==2.0.0
# via pytest
Expand Down Expand Up @@ -80,7 +80,7 @@ pytz==2024.2
# pandas
pyyaml==6.0.2
# via libcst
redis==5.0.8
redis==5.1.0
# via fakeredis
six==1.16.0
# via python-dateutil
Expand All @@ -98,5 +98,5 @@ typing-extensions==4.12.2
# -r requirements/coverage.in
# black
# fakeredis
tzdata==2024.1
tzdata==2024.2
# via pandas
8 changes: 4 additions & 4 deletions requirements/fuzzing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ exceptiongroup==1.2.2 ; python_version < "3.11"
# pytest
execnet==2.1.1
# via pytest-xdist
fakeredis==2.24.1
fakeredis==2.25.0
# via -r requirements/coverage.in
flask==3.0.3
# via dash
hypofuzz==24.2.3
hypofuzz==24.9.1
# via -r requirements/fuzzing.in
hypothesis[cli]==6.112.1
# via hypofuzz
Expand Down Expand Up @@ -139,7 +139,7 @@ pytz==2024.2
# pandas
pyyaml==6.0.2
# via libcst
redis==5.0.8
redis==5.1.0
# via fakeredis
requests==2.32.3
# via
Expand Down Expand Up @@ -171,7 +171,7 @@ typing-extensions==4.12.2
# black
# dash
# fakeredis
tzdata==2024.1
tzdata==2024.2
# via pandas
urllib3==2.2.3
# via requests
Expand Down
13 changes: 7 additions & 6 deletions requirements/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jaraco-classes==3.4.0
# via keyring
jaraco-context==6.0.1
# via keyring
jaraco-functools==4.0.2
jaraco-functools==4.1.0
# via keyring
jedi==0.19.1
# via ipython
Expand Down Expand Up @@ -167,7 +167,7 @@ parso==0.8.4
# via jedi
pathspec==0.12.1
# via black
pelican[markdown]==4.10.0
pelican[markdown]==4.10.1
# via -r requirements/tools.in
pexpect==4.9.0
# via ipython
Expand All @@ -184,7 +184,7 @@ pluggy==1.5.0
# via
# pytest
# tox
prompt-toolkit==3.0.47
prompt-toolkit==3.0.48
# via ipython
ptyprocess==0.7.0
# via pexpect
Expand All @@ -207,7 +207,7 @@ pyproject-hooks==1.1.0
# via
# build
# pip-tools
pyright==1.1.381
pyright==1.1.382.post1
# via -r requirements/tools.in
pytest==8.3.3
# via -r requirements/tools.in
Expand Down Expand Up @@ -242,7 +242,7 @@ rich==13.8.1
# via
# pelican
# twine
ruff==0.6.7
ruff==0.6.8
# via -r requirements/tools.in
secretstorage==3.3.3
# via keyring
Expand Down Expand Up @@ -338,13 +338,14 @@ typing-extensions==4.12.2
# black
# ipython
# mypy
# pyright
unidecode==1.3.8
# via pelican
urllib3==2.2.3
# via
# requests
# twine
virtualenv==20.26.5
virtualenv==20.26.6
# via tox
watchfiles==0.24.0
# via pelican
Expand Down

0 comments on commit 3c1350d

Please sign in to comment.