Skip to content

Commit 2bc3b05

Browse files
authored
Merge c55ed63 into 3022733
2 parents 3022733 + c55ed63 commit 2bc3b05

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

docs/source/changes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
77
`Anaconda.org <https://anaconda.org/conda-forge/pytask>`_.
88

99

10+
0.1.7 - 2022-01-28
11+
------------------
12+
13+
- :gh:`153` adds support for Python 3.10 which requires pony >= 0.7.15.
14+
- :gh:`192` deprecates Python 3.6.
15+
- :gh:`209` cancels previous CI jobs when a new job is started.
16+
- :gh:`210` allows ``__tracebackhide__`` to be a callable which accepts the current
17+
exception as an input. Closes :gh:`145`.
18+
19+
1020
0.1.6 - 2022-01-27
1121
------------------
1222

src/_pytask/traceback.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,43 @@ def remove_internal_traceback_frames_from_exc_info(
5757
"""
5858
if exc_info is not None:
5959
if isinstance(exc_info[2], TracebackType):
60-
filtered_traceback = _filter_internal_traceback_frames(exc_info[2])
60+
filtered_traceback = _filter_internal_traceback_frames(exc_info)
6161
exc_info = (*exc_info[:2], filtered_traceback)
6262

6363
return exc_info
6464

6565

66-
def _is_internal_or_hidden_traceback_frame(frame: TracebackType) -> bool:
66+
def _is_internal_or_hidden_traceback_frame(
67+
frame: TracebackType, exc_info: ExceptionInfo
68+
) -> bool:
6769
"""Returns ``True`` if traceback frame belongs to internal packages or is hidden.
6870
6971
Internal packages are ``_pytask`` and ``pluggy``. A hidden frame is indicated by a
7072
local variable called ``__tracebackhide__ = True``.
7173
7274
"""
7375
is_hidden = frame.tb_frame.f_locals.get("__tracebackhide__", False)
74-
if is_hidden:
76+
77+
if callable(is_hidden):
78+
return is_hidden(exc_info)
79+
elif is_hidden:
7580
return True
7681

7782
path = Path(frame.tb_frame.f_code.co_filename)
7883
return any(root in path.parents for root in [_PLUGGY_DIRECTORY, _PYTASK_DIRECTORY])
7984

8085

8186
def _filter_internal_traceback_frames(
82-
frame: TracebackType,
87+
exc_info: ExceptionInfo,
8388
) -> TracebackType:
8489
"""Filter internal traceback frames from traceback.
8590
8691
If the first external frame is visited, return the frame. Else return ``None``.
8792
8893
"""
94+
frame = exc_info[2]
8995
for frame in _yield_traceback_frames(frame):
90-
if frame is None or not _is_internal_or_hidden_traceback_frame(frame):
96+
if frame is None or not _is_internal_or_hidden_traceback_frame(frame, exc_info):
9197
break
9298
return frame
9399

tests/test_traceback.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@
88

99

1010
@pytest.mark.end_to_end
11-
@pytest.mark.parametrize("is_hidden", [True, False])
12-
def test_hide_traceback_from_error_report(runner, tmp_path, is_hidden):
11+
@pytest.mark.parametrize(
12+
"value, exception, is_hidden",
13+
[
14+
("True", "Exception", True),
15+
("False", "Exception", False),
16+
("lambda exc_info: True", "Exception", True),
17+
("lambda exc_info: False", "Exception", False),
18+
("lambda exc_info: isinstance(exc_info[1], ValueError)", "ValueError", True),
19+
("lambda exc_info: isinstance(exc_info[1], ValueError)", "TypeError", False),
20+
],
21+
)
22+
def test_hide_traceback_from_error_report(
23+
runner, tmp_path, value, exception, is_hidden
24+
):
1325
source = f"""
1426
def task_main():
1527
a = "This variable should not be shown."
16-
__tracebackhide__ = {is_hidden}
28+
__tracebackhide__ = {value}
1729
1830
1931
helper()
2032
2133
2234
def helper():
23-
raise Exception
35+
raise {exception}
2436
"""
2537
tmp_path.joinpath("task_main.py").write_text(textwrap.dedent(source))
2638

0 commit comments

Comments
 (0)