Skip to content

Commit dcb4121

Browse files
committed
Use exceptiongroup backport
1 parent f181149 commit dcb4121

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

hypothesis-python/setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ def local_file(name):
100100
description="A library for property-based testing",
101101
zip_safe=False,
102102
extras_require=extras,
103-
install_requires=["attrs>=19.2.0", "sortedcontainers>=2.1.0,<3.0.0"],
103+
install_requires=[
104+
"attrs>=19.2.0",
105+
"exceptiongroup>=1.0.0rc8 ; python_version<'3.11.0b1'",
106+
"sortedcontainers>=2.1.0,<3.0.0",
107+
],
104108
python_requires=">=3.7",
105109
classifiers=[
106110
"Development Status :: 5 - Production/Stable",

hypothesis-python/src/hypothesis/internal/compat.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
try:
1818
BaseExceptionGroup = BaseExceptionGroup
19-
except NameError: # pragma: no cover
20-
try:
21-
from exceptiongroup import BaseExceptionGroup as BaseExceptionGroup # for mypy
22-
except ImportError:
23-
BaseExceptionGroup = () # valid in isinstance and except clauses!
19+
ExceptionGroup = ExceptionGroup # pragma: no cover
20+
except NameError:
21+
from exceptiongroup import (
22+
BaseExceptionGroup as BaseExceptionGroup,
23+
ExceptionGroup as ExceptionGroup,
24+
)
2425

2526
PYPY = platform.python_implementation() == "PyPy"
2627
WINDOWS = platform.system() == "Windows"

hypothesis-python/src/hypothesis/strategies/_internal/types.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from hypothesis import strategies as st
3030
from hypothesis.errors import InvalidArgument, ResolutionFailed
31-
from hypothesis.internal.compat import PYPY
31+
from hypothesis.internal.compat import PYPY, BaseExceptionGroup, ExceptionGroup
3232
from hypothesis.internal.conjecture.utils import many as conjecture_utils_many
3333
from hypothesis.strategies._internal.datetime import zoneinfo # type: ignore
3434
from hypothesis.strategies._internal.ipaddress import (
@@ -554,6 +554,16 @@ def _networks(bits):
554554
UnicodeTranslateError: st.builds(
555555
UnicodeTranslateError, st.text(), st.just(0), st.just(0), st.just("reason")
556556
),
557+
BaseExceptionGroup: st.builds(
558+
BaseExceptionGroup,
559+
st.text(),
560+
st.lists(st.from_type(BaseException), min_size=1),
561+
),
562+
ExceptionGroup: st.builds(
563+
ExceptionGroup,
564+
st.text(),
565+
st.lists(st.from_type(Exception), min_size=1),
566+
),
557567
enumerate: st.builds(enumerate, st.just(())),
558568
filter: st.builds(filter, st.just(lambda _: None), st.just(())),
559569
map: st.builds(map, st.just(lambda _: None), st.just(())),
@@ -569,21 +579,6 @@ def _networks(bits):
569579
_global_type_lookup[zoneinfo.ZoneInfo] = st.timezones()
570580
if PYPY:
571581
_global_type_lookup[builtins.sequenceiterator] = st.builds(iter, st.tuples()) # type: ignore
572-
try:
573-
BaseExceptionGroup # type: ignore # noqa
574-
except NameError:
575-
pass
576-
else: # pragma: no cover
577-
_global_type_lookup[BaseExceptionGroup] = st.builds( # type: ignore
578-
BaseExceptionGroup, # type: ignore
579-
st.text(),
580-
st.lists(st.from_type(BaseException), min_size=1),
581-
)
582-
_global_type_lookup[ExceptionGroup] = st.builds( # type: ignore
583-
ExceptionGroup, # type: ignore
584-
st.text(),
585-
st.lists(st.from_type(Exception), min_size=1),
586-
)
587582

588583

589584
_global_type_lookup[type] = st.sampled_from(

0 commit comments

Comments
 (0)