Skip to content

Commit 102430c

Browse files
authored
Merge pull request #2 from sdispater/fix-frames-with-no-context
Fix an error when trying to get the line of a no context frame
2 parents fbcea96 + 88aac6b commit 102430c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

crashtest/frame.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import inspect
22

3-
from types import TracebackType
3+
from types import FrameType
44
from typing import Dict
55

66

@@ -17,7 +17,7 @@ def __init__(self, frame_info: inspect.FrameInfo) -> None:
1717
self._file_content = None
1818

1919
@property
20-
def frame(self) -> TracebackType:
20+
def frame(self) -> FrameType:
2121
return self._frame
2222

2323
@property
@@ -34,6 +34,9 @@ def function(self) -> str:
3434

3535
@property
3636
def line(self) -> str:
37+
if not self._frame_info.code_context:
38+
return ""
39+
3740
return self._frame_info.code_context[0]
3841

3942
@property

tests/test_frame.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ def test_frame():
3535
assert other_frame != frame
3636
assert hash(same_frame) == hash(frame)
3737
assert hash(other_frame) != hash(frame)
38+
39+
40+
def test_frame_with_no_context_should_return_empty_line():
41+
frame = Frame(inspect.FrameInfo(None, "filename.py", 123, "function", None, 3))
42+
43+
assert "" == frame.line

0 commit comments

Comments
 (0)