Skip to content

Commit d578c52

Browse files
committed
fix: don't assume we have a current frame. #2005
1 parent ecf53d5 commit d578c52

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

CHANGES.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Unreleased
6262
- We no longer ship a PyPy-specific wheel. PyPy will install the pure-Python
6363
wheel. Closes `issue 2001`_.
6464

65+
- In the very unusual situation of not having a current frame, coverage no
66+
longer crashes when using the sysmon core, fixing `issue 2005`_.
67+
6568
.. _issue 310: https://github.com/nedbat/coveragepy/issues/310
6669
.. _issue 312: https://github.com/nedbat/coveragepy/issues/312
6770
.. _issue 367: https://github.com/nedbat/coveragepy/issues/367
@@ -73,7 +76,7 @@ Unreleased
7376
.. _issue 1941: https://github.com/nedbat/coveragepy/issues/1941
7477
.. _pull 1998: https://github.com/nedbat/coveragepy/pull/1998
7578
.. _issue 2001: https://github.com/nedbat/coveragepy/issues/2001
76-
79+
.. _issue 2005: https://github.com/nedbat/coveragepy/issues/2005
7780

7881
.. start-releases
7982

coverage/sysmon.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,12 @@ def sysmon_py_start(
318318
filename = code.co_filename
319319
disp = self.should_trace_cache.get(filename)
320320
if disp is None:
321-
frame = inspect.currentframe().f_back # type: ignore[union-attr]
322-
if LOG:
323-
# @panopticon adds a frame.
324-
frame = frame.f_back # type: ignore[union-attr]
321+
frame = inspect.currentframe()
322+
if frame is not None:
323+
frame = inspect.currentframe().f_back # type: ignore[union-attr]
324+
if LOG:
325+
# @panopticon adds a frame.
326+
frame = frame.f_back # type: ignore[union-attr]
325327
disp = self.should_trace(filename, frame) # type: ignore[arg-type]
326328
self.should_trace_cache[filename] = disp
327329

0 commit comments

Comments
 (0)