Skip to content

Commit

Permalink
chore: fix mypy findings
Browse files Browse the repository at this point in the history
  • Loading branch information
P403n1x87 committed Jul 2, 2021
1 parent 6892db9 commit 5dece89
Show file tree
Hide file tree
Showing 12 changed files with 442 additions and 298 deletions.
8 changes: 4 additions & 4 deletions austin_tui/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from typing import Any, List, Optional

from austin import AustinError
from austin import AustinTerminated
from austin.aio import AsyncAustin
from austin.cli import AustinArgumentParser
from austin.cli import AustinCommandLineError
Expand Down Expand Up @@ -75,7 +74,7 @@ def __init__(self) -> None:

self._args = AustinTUIArgumentParser().parse_args()

self._view: AustinView = ViewBuilder.from_resource(
self._view: AustinView = ViewBuilder.from_resource( # type: ignore[assignment]
"austin_tui.view", "tui.austinui"
)
mode = AustinProfileMode.MEMORY if self._args.memory else AustinProfileMode.TIME
Expand Down Expand Up @@ -137,6 +136,9 @@ def run(self) -> None:
self.start(AustinTUIArgumentParser.to_list(self._args))
)
loop.run_forever()

self._view.close()

if not austin.done():
austin.cancel()

Expand All @@ -153,8 +155,6 @@ def shutdown(self) -> None:
except AustinError:
pass

self._view.close()

asyncio.get_event_loop().stop()


Expand Down
2 changes: 1 addition & 1 deletion austin_tui/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Controller(ABC):

def __init__(self, view: View) -> None:
self.view = view
self.model = self.__model__(view.mode)
self.model = self.__model__(view.mode) # type: ignore[call-arg]

def push(self, event: Event, data: Any = None) -> Any:
"""Push an event to the controller.
Expand Down
2 changes: 1 addition & 1 deletion austin_tui/controllers/austin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AustinController(Controller):
This controller is in charge of Austin data managing and UI updates.
"""

__model__ = AustinModel
__model__ = AustinModel # type: ignore[assignment]

def __init__(self, view: View) -> None:
super().__init__(view)
Expand Down
2 changes: 1 addition & 1 deletion austin_tui/controllers/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SystemController(Controller):
fresh system data (e.g. CPU usage, duration etc...).
"""

__model__ = SystemModel
__model__ = SystemModel # type: ignore[assignment]

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
Expand Down
7 changes: 4 additions & 3 deletions austin_tui/view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from abc import ABC
import asyncio
import curses
import sys
Expand Down Expand Up @@ -80,15 +81,15 @@ def _validate_ns(node: Element) -> None:
raise ViewBuilderError(f"Node '{node}' has invalid namespace")


class View:
class View(ABC):
"""View object.
All coroutines are collected and scheduled for execution when the view is
opened.
"""

def __init__(self, name: str) -> None:
self._tasks = []
self._tasks: List[asyncio.Task] = []

self._event_handlers: Dict[str, EventHandler] = {}

Expand All @@ -98,7 +99,7 @@ def __init__(self, name: str) -> None:
self.palette = Palette()
self.root_widget = None

def _create_tasks(self) -> List[asyncio.Task]:
def _create_tasks(self) -> None:
loop = asyncio.get_event_loop()
self._tasks = [
loop.create_task(coro())
Expand Down
3 changes: 2 additions & 1 deletion austin_tui/view/austin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def on_quit(self) -> bool:
"""Handle Quit event."""
if not self.callback:
raise RuntimeError("AustinTUI requires a callback to handle quit events.")
self.callback(self.Event.QUIT)
self.callback(self.Event.QUIT, None)
return False

def on_next_thread(self) -> bool:
"""Handle next thread event."""
Expand Down
4 changes: 2 additions & 2 deletions austin_tui/widgets/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def attr(self) -> int:
attr |= curses.A_REVERSE
return attr

def write(
def write( # type: ignore[override]
self, window: "curses._CursesWindow", y: int, x: int, maxlen: int = None
) -> int:
"""Write the chunk on the given curses window.
Expand Down Expand Up @@ -129,7 +129,7 @@ def __len__(self) -> int:
"""The actual string length."""
return sum(len(_) for _ in self._chunks)

def write(
def write( # type: ignore[override]
self, window: "curses._CursesWindow", y: int, x: int, maxlen: int = None
) -> int:
"""Write the attribute string on the given window.
Expand Down
2 changes: 1 addition & 1 deletion austin_tui/widgets/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _draw_row(self, i: int, row: List[Any]) -> None:
else:
text = row[j]
win.addstr(i, x, text[: available - x], 0)
delta = min(text[: available - x], len(text))
delta = min(available - x, len(text))
x += delta

def set_data(self, data: TableData) -> None:
Expand Down
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[mypy]
disable_error_code = attr-defined,import,union-attr

[mypy-nox.*,pytest,psutil]
ignore_missing_imports = True
Expand Down
5 changes: 2 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import nox


nox.options.sessions = ["lint"]
nox.options.sessions = ["lint", "mypy"]


# ---- Configuration ----
Expand Down Expand Up @@ -59,7 +58,7 @@ def lint(session):
@nox.session(python=SUPPORTED_PYTHON_VERSIONS)
def mypy(session):
session.install("mypy")
session.run("mypy", *MYPY_LOCATIONS)
session.run("mypy", "--show-error-codes", *MYPY_LOCATIONS)


@nox.session(python="3.7")
Expand Down
Loading

0 comments on commit 5dece89

Please sign in to comment.