Skip to content

Commit

Permalink
Assert that we have frame information.
Browse files Browse the repository at this point in the history
@willmcgugan I went with the asserts because the tone of the code tells me that we are kind of certain that the current and previous frames always exist. Should the function be refactored to handle None for the previous frame (or the current & previous frames) by writing to the buffer without caller information, for example?
  • Loading branch information
rodrigogiraoserrao committed Feb 17, 2023
1 parent e93b7e2 commit b709219
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 2 additions & 4 deletions mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ src/textual/_two_way_dict.py:41: error: Incompatible return value type (got "Opt
src/textual/_two_way_dict.py:52: error: Incompatible return value type (got "Optional[Key]", expected "Key") [return-value]
src/textual/devtools/service.py:10: error: Skipping analyzing "msgpack": module is installed, but missing library stubs or py.typed marker [import]
src/textual/devtools/client.py:13: error: Skipping analyzing "msgpack": module is installed, but missing library stubs or py.typed marker [import]
src/textual/devtools/redirect_output.py:42: error: Item "None" of "Optional[FrameType]" has no attribute "f_back" [union-attr]
src/textual/devtools/redirect_output.py:43: error: Argument 1 to "getframeinfo" has incompatible type "Union[FrameType, None, Any]"; expected "Union[FrameType, TracebackType]" [arg-type]
src/textual/devtools/redirect_output.py:45: error: Argument "caller" to "DevtoolsLog" has incompatible type "Traceback"; expected "FrameInfo" [arg-type]
src/textual/devtools/redirect_output.py:48: error: Argument "caller" to "DevtoolsLog" has incompatible type "Traceback"; expected "FrameInfo" [arg-type]
src/textual/__init__.py:27: error: Library stubs not installed for "pkg_resources" [import]
src/textual/__init__.py:27: note: Hint: "python3 -m pip install types-setuptools"
src/textual/__init__.py:27: note: (or run "mypy --install-types" to install all missing stub packages)
Expand Down Expand Up @@ -92,4 +90,4 @@ src/textual/demo.py:221: error: "App[Any]" has no attribute "add_note" [attr-de
src/textual/demo.py:276: error: "App[Any]" has no attribute "add_note" [attr-defined]
src/textual/cli/previews/easing.py:102: error: Argument "easing" to "animate" of "App" has incompatible type "Optional[str]"; expected "Union[Callable[[float], float], str]" [arg-type]
src/textual/cli/previews/easing.py:111: error: "MessageTarget" has no attribute "id" [attr-defined]
Found 84 errors in 28 files (checked 152 source files)
Found 82 errors in 28 files (checked 152 source files)
5 changes: 4 additions & 1 deletion src/textual/devtools/redirect_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def write(self, string: str) -> None:
if not self.devtools.is_connected:
return

previous_frame = inspect.currentframe().f_back
current_frame = inspect.currentframe()
assert current_frame is not None
previous_frame = current_frame.f_back
assert previous_frame is not None
caller = inspect.getframeinfo(previous_frame)

self._buffer.append(DevtoolsLog(string, caller=caller))
Expand Down
4 changes: 2 additions & 2 deletions src/textual/devtools/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import json
import pickle
from json import JSONDecodeError
from typing import Any, cast
from typing import Any

import msgpack
from aiohttp import WSMessage, WSMsgType
from aiohttp import WSMsgType
from aiohttp.abc import Request
from aiohttp.web_ws import WebSocketResponse
from rich.console import Console
Expand Down

0 comments on commit b709219

Please sign in to comment.