Skip to content

Commit

Permalink
Fix an error when trying to get the line of a no context frame
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Jul 31, 2020
1 parent fbcea96 commit 88aac6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crashtest/frame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect

from types import TracebackType
from types import FrameType
from typing import Dict


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

@property
def frame(self) -> TracebackType:
def frame(self) -> FrameType:
return self._frame

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

@property
def line(self) -> str:
if not self._frame_info.code_context:
return ""

return self._frame_info.code_context[0]

@property
Expand Down
6 changes: 6 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ def test_frame():
assert other_frame != frame
assert hash(same_frame) == hash(frame)
assert hash(other_frame) != hash(frame)


def test_frame_with_no_context_should_return_empty_line():
frame = Frame(inspect.FrameInfo(None, "filename.py", 123, "function", None, 3))

assert "" == frame.line

0 comments on commit 88aac6b

Please sign in to comment.