MCPcopy Index your code
hub / github.com/ipython/ipython / _exceptiongroup_common

Function _exceptiongroup_common

tests/test_exceptiongroup_tb.py:10–95  ·  view source on GitHub ↗
(
    outer_chain: str,
    inner_chain: str,
    native: bool,
)

Source from the content-addressed store, hash-verified

8
9
10def _exceptiongroup_common(
11 outer_chain: str,
12 inner_chain: str,
13 native: bool,
14) -> None:
15 pre_raise = "exceptiongroup." if not native else ""
16 filestr = f"""
17 {"import exceptiongroup" if not native else ""}
18 import pytest
19
20 def f(): raise ValueError("From f()")
21 def g(): raise BaseException("From g()")
22
23 def inner(inner_chain):
24 excs = []
25 for callback in [f, g]:
26 try:
27 callback()
28 except BaseException as err:
29 excs.append(err)
30 if excs:
31 if inner_chain == "none":
32 raise {pre_raise}BaseExceptionGroup("Oops", excs)
33 try:
34 raise SyntaxError()
35 except SyntaxError as e:
36 if inner_chain == "from":
37 raise {pre_raise}BaseExceptionGroup("Oops", excs) from e
38 else:
39 raise {pre_raise}BaseExceptionGroup("Oops", excs)
40
41 def outer(outer_chain, inner_chain):
42 try:
43 inner(inner_chain)
44 except BaseExceptionGroup as e:
45 if outer_chain == "none":
46 raise
47 if outer_chain == "from":
48 raise IndexError() from e
49 else:
50 raise IndexError
51
52
53 outer("{outer_chain}", "{inner_chain}")
54 """
55 with capture_output() as cap:
56 ip.run_cell(filestr)
57
58 match_lines = []
59 if inner_chain == "another":
60 match_lines += [
61 "During handling of the above exception, another exception occurred:",
62 ]
63 elif inner_chain == "from":
64 match_lines += [
65 "The above exception was the direct cause of the following exception:",
66 ]
67

Callers 1

Calls 2

capture_outputClass · 0.90
run_cellMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…