Skip to content

Commit 388e6d1

Browse files
committed
No namedtuple for this sadly
1 parent 91f7722 commit 388e6d1

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

hypothesis-python/src/hypothesis/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
from hypothesis.internal.conjecture.shrinker import sort_key
7575
from hypothesis.internal.entropy import deterministic_PRNG
7676
from hypothesis.internal.escalation import (
77-
InterestingOrigin,
7877
escalate_hypothesis_internal_error,
7978
format_exception,
79+
get_interesting_origin,
8080
get_trimmed_traceback,
8181
)
8282
from hypothesis.internal.healthcheck import fail_health_check
@@ -742,7 +742,7 @@ def _execute_once_for_engine(self, data):
742742

743743
self.failed_normally = True
744744

745-
interesting_origin = InterestingOrigin.from_exception(e)
745+
interesting_origin = get_interesting_origin(e)
746746
if trace: # pragma: no cover
747747
# Trace collection is explicitly disabled under coverage.
748748
self.explain_traces[interesting_origin].add(trace)

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import traceback
1515
from inspect import getframeinfo
1616
from pathlib import Path
17-
from typing import Dict, NamedTuple, Optional, Tuple, Type
17+
from typing import Dict
1818

1919
import hypothesis
2020
from hypothesis.errors import (
@@ -103,35 +103,29 @@ def get_trimmed_traceback(exception=None):
103103
return tb
104104

105105

106-
class InterestingOrigin(NamedTuple):
106+
def get_interesting_origin(exception):
107107
# The `interesting_origin` is how Hypothesis distinguishes between multiple
108108
# failures, for reporting and also to replay from the example database (even
109109
# if report_multiple_bugs=False). We traditionally use the exception type and
110110
# location, but have extracted this logic in order to see through `except ...:`
111111
# blocks and understand the __cause__ (`raise x from y`) or __context__ that
112112
# first raised an exception as well as PEP-654 exception groups.
113-
type_: Type[BaseException]
114-
filename: str
115-
lineno: int
116-
context: "Optional[InterestingOrigin]"
117-
exceptiongroup_contents: "Optional[Tuple[InterestingOrigin, ...]]"
118-
119-
@classmethod
120-
def from_exception(cls, exception: BaseException) -> "InterestingOrigin":
121-
tb = get_trimmed_traceback(exception)
122-
filename, lineno, *_ = traceback.extract_tb(tb)[-1]
113+
tb = get_trimmed_traceback(exception)
114+
filename, lineno, *_ = traceback.extract_tb(tb)[-1]
115+
return (
116+
type(exception),
117+
filename,
118+
lineno,
123119
# Note that if __cause__ is set it is always equal to __context__, explicitly
124120
# to support introspection when debugging, so we can use that unconditionally.
125-
chained_from = exception.__context__
126-
return cls(
127-
type(exception),
128-
filename,
129-
lineno,
130-
cls.from_exception(chained_from) if chained_from else None,
131-
tuple(map(cls.from_exception, exception.exceptions))
121+
get_interesting_origin(exception.__context__) if exception.__context__ else (),
122+
# We distinguish exception groups by the inner exceptions, as for __context__
123+
tuple(
124+
map(get_interesting_origin, exception.exceptions)
132125
if isinstance(exception, BaseExceptionGroup)
133-
else None,
134-
)
126+
else []
127+
),
128+
)
135129

136130

137131
current_pytest_item = DynamicVariable(None)

0 commit comments

Comments
 (0)