From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E845C432BE for ; Tue, 10 Aug 2021 17:14:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BAEE0600EF for ; Tue, 10 Aug 2021 17:14:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BAEE0600EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:45936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDVKI-0002tK-0O for qemu-devel@archiver.kernel.org; Tue, 10 Aug 2021 13:14:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDVJZ-0001ix-5z for qemu-devel@nongnu.org; Tue, 10 Aug 2021 13:13:21 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]:40659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mDVJV-00028I-P0 for qemu-devel@nongnu.org; Tue, 10 Aug 2021 13:13:20 -0400 Received: by mail-il1-x12c.google.com with SMTP id u7so1244565ilk.7 for ; Tue, 10 Aug 2021 10:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UZcomO3PWq7h5Kaij4CM7scqCxvBLI3+kUw/hudaSDc=; b=S9gg7t8Za3v3cWNhRIdYkKykYu0+m/cYgs7fTNLteRbIDD8fuNapLG5pkl1liPL8I5 oFRUzxYs/vXmYISSHHdVewN680EKkJmrUkfYInw4LJZQIsHiybxLsBvuEwfczpSIIK7m qyudQbRv76rOpH7gCqhYQ8c6XG24ErgzqlsrkO3o6TBEU7o/kVXGexTgSunUVBCnzPpx C3vNs61fMtQhXIT9dQi2Fju3wp/qc6jzHY7GmRhCuFaT/zVwE05t+NNx5oiJWmSMcIqb zIWvcWXqlye9Fc4SF6loW4/lBLQsnCEevbLv6RijLwWcV0dP2cWk0vh3SMKh+A0iAr5g T6Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UZcomO3PWq7h5Kaij4CM7scqCxvBLI3+kUw/hudaSDc=; b=tulD+aJNhAd17ryuJIvC2LxipQXCSCoQhCjlbLkNt4aNUMPCeyw3qC9wDNeazSpKk9 KhQ/VvbVKh3TjBc6a3ZKV2rB/BraMBkjgubcXkB+mDrJnW3sMbwIrgMHrWnvjVfbNYNs Qx3pjKTSLEABjceLz+3eGigj65r1Rd+V0kYRCKctTg1iYmflG/iP8J34Bj6F5ltFHRR2 SVAr5QH8cZfn58f13Hi6+R9JVYlzuUpGtpu6TLeokgrFGu8L/NS/6fkTW0KPpc+24r4X 5Q0014l6Zc2PMFgMbQRfKOmX0uww2Jyoe64x5suGvFRXOSczwyz8uH0Oc6kwa0VL4iJ6 yu8A== X-Gm-Message-State: AOAM531Ep28gQwqZuCrdGJdImDwzvZ7pt/Nygear98KCJdmj+o8p84yV HZaBismCRooFbEeTBTK8FL3goZ3DceZrmysL+Iw= X-Google-Smtp-Source: ABdhPJwPnzlSOJptL52Q2lWj5DK3aJMt1DyfmwdH8HZkifXJdaB2SIJ7IsGfTaIAh4aNddjqJbxWgbyyfXWpb0vgSFc= X-Received: by 2002:a92:a04c:: with SMTP id b12mr47149ilm.80.1628615595933; Tue, 10 Aug 2021 10:13:15 -0700 (PDT) MIME-Version: 1.0 References: <20210730201846.5147-1-niteesh.gs@gmail.com> <20210730201846.5147-7-niteesh.gs@gmail.com> In-Reply-To: From: "Niteesh G. S." Date: Tue, 10 Aug 2021 22:42:50 +0530 Message-ID: Subject: Re: [PATCH v3 06/13] python/aqmp-tui: Added type annotations for aqmp-tui To: John Snow Content-Type: multipart/alternative; boundary="0000000000001243fe05c9379ed4" Received-SPF: pass client-ip=2607:f8b0:4864:20::12c; envelope-from=niteesh.gs@gmail.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Kashyap Chamarthy , Markus Armbruster , Wainer Moschetta , qemu-devel , Stefan Hajnoczi , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --0000000000001243fe05c9379ed4 Content-Type: text/plain; charset="UTF-8" On Fri, Aug 6, 2021 at 1:26 AM John Snow wrote: > > > On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu > wrote: > >> This patch adds type annotations for aqmp-tui using >> the mypy library. >> >> > Awesome, thanks for taking a swing at this. Looks like it wasn't as bad as > I was fearing. > > >> Signed-off-by: G S Niteesh Babu >> --- >> python/qemu/aqmp/aqmp_tui.py | 79 ++++++++++++++++++++---------------- >> python/setup.cfg | 3 -- >> 2 files changed, 43 insertions(+), 39 deletions(-) >> >> diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py >> index ec9eba0aa7..ab9ada793a 100644 >> --- a/python/qemu/aqmp/aqmp_tui.py >> +++ b/python/qemu/aqmp/aqmp_tui.py >> @@ -9,8 +9,15 @@ >> import argparse >> import asyncio >> import logging >> -from logging import Handler >> +from logging import Handler, LogRecord >> import signal >> +from typing import ( >> + Any, >> + List, >> + Optional, >> + Tuple, >> + Union, >> +) >> >> import urwid >> import urwid_readline >> @@ -22,13 +29,13 @@ >> from .util import create_task, pretty_traceback >> >> >> -UPDATE_MSG = 'UPDATE_MSG' >> +UPDATE_MSG: str = 'UPDATE_MSG' >> >> # Using root logger to enable all loggers under qemu and asyncio >> LOGGER = logging.getLogger() >> >> >> -def format_json(msg): >> +def format_json(msg: str) -> str: >> """ >> Formats given multiline JSON message into a single line message. >> Converting into single line is more asthetically pleasing when >> looking >> @@ -43,17 +50,17 @@ def format_json(msg): >> >> >> class App(QMPClient): >> - def __init__(self, address): >> + def __init__(self, address: Union[str, Tuple[str, int]]) -> None: >> urwid.register_signal(type(self), UPDATE_MSG) >> self.window = Window(self) >> self.address = address >> - self.aloop = None >> + self.aloop: Optional[Any] = None # FIXME: Use more concrete >> type. >> > > I ran into this in util.py; you want Optional[asyncio.AbstractEventLoop] > here. > Thanks. Fixed. > > >> super().__init__() >> >> - def add_to_history(self, msg): >> + def add_to_history(self, msg: str) -> None: >> urwid.emit_signal(self, UPDATE_MSG, msg) >> >> - def _cb_outbound(self, msg): >> + def _cb_outbound(self, msg: Message) -> Message: >> # FIXME: I think the ideal way to omit these messages during >> in-TUI >> # logging will be to add a filter to the logger. We can use >> regex to >> # filter out messages starting with 'Request:' or 'Response:' >> but I >> @@ -67,25 +74,25 @@ def _cb_outbound(self, msg): >> self.add_to_history('<-- ' + str(msg)) >> return msg >> >> - def _cb_inbound(self, msg): >> + def _cb_inbound(self, msg: Message) -> Message: >> handler = LOGGER.handlers[0] >> if not isinstance(handler, TUILogHandler): >> LOGGER.debug('Response: %s', str(msg)) >> self.add_to_history('--> ' + str(msg)) >> return msg >> >> - async def wait_for_events(self): >> + async def wait_for_events(self) -> None: >> async for event in self.events: >> self.handle_event(event) >> >> - async def _send_to_server(self, raw_msg): >> + async def _send_to_server(self, raw_msg: str) -> None: >> # FIXME: Format the raw_msg in history view to one line. It is >> not >> # pleasing to see multiple lines JSON object with an error >> statement. >> try: >> msg = Message(bytes(raw_msg, encoding='utf-8')) >> # Format multiline json into a single line JSON, since it is >> more >> # pleasing to look along with err message in TUI. >> - raw_msg = self.format_json(raw_msg) >> + raw_msg = format_json(raw_msg) >> await self._raw(msg, assign_id='id' not in msg) >> except (ValueError, TypeError) as err: >> LOGGER.info('Invalid message: %s', str(err)) >> @@ -102,18 +109,18 @@ def _cb_inbound(self, msg): >> LOGGER.error('Exception from _send_to_server: %s', str(err)) >> raise err >> >> - def cb_send_to_server(self, msg): >> + def cb_send_to_server(self, msg: str) -> None: >> create_task(self._send_to_server(msg)) >> >> - def unhandled_input(self, key): >> + def unhandled_input(self, key: str) -> None: >> if key == 'esc': >> self.kill_app() >> >> - def kill_app(self): >> + def kill_app(self) -> None: >> # TODO: Work on the disconnect logic >> create_task(self._kill_app()) >> >> - async def _kill_app(self): >> + async def _kill_app(self) -> None: >> # It is ok to call disconnect even in disconnect state >> try: >> await self.disconnect() >> @@ -124,7 +131,7 @@ def kill_app(self): >> raise err >> raise urwid.ExitMainLoop() >> >> - def handle_event(self, event): >> + def handle_event(self, event: Message) -> None: >> # FIXME: Consider all states present in qapi/run-state.json >> if event['event'] == 'SHUTDOWN': >> self._set_status('Server shutdown') >> @@ -139,7 +146,7 @@ def _get_formatted_address(self) -> str: >> addr = f'{host}:{port}' >> return addr >> >> - async def connect_server(self): >> + async def connect_server(self) -> None: >> try: >> await self.connect(self.address) >> addr = self._get_formatted_address() >> @@ -148,7 +155,7 @@ def _get_formatted_address(self) -> str: >> LOGGER.info('connect_server: ConnectError %s', str(err)) >> self._set_status('Server shutdown') >> >> - def run(self, debug=False): >> + def run(self, debug: bool = False) -> None: >> self.aloop = asyncio.get_event_loop() >> self.aloop.set_debug(debug) >> >> @@ -176,7 +183,7 @@ class StatusBar(urwid.Text): >> """ >> A simple Text widget that currently only shows connection status. >> """ >> - def __init__(self, text=''): >> + def __init__(self, text: str = ''): >> super().__init__(text, align='right') >> >> >> @@ -185,14 +192,14 @@ class Editor(urwid_readline.ReadlineEdit): >> Support urwid_readline features along with >> history support which lacks in urwid_readline >> """ >> - def __init__(self, master): >> + def __init__(self, master: App) -> None: >> super().__init__(caption='> ', multiline=True) >> self.master = master >> - self.history = [] >> - self.last_index = -1 >> - self.show_history = False >> + self.history: List[str] = [] >> + self.last_index: int = -1 >> + self.show_history: bool = False >> >> - def keypress(self, size, key): >> + def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]: >> # TODO: Add some logic for down key and clean up logic if >> possible. >> # Returning None means the key has been handled by this widget >> # which otherwise is propogated to the parent widget to be >> @@ -223,7 +230,7 @@ def keypress(self, size, key): >> else: >> self.show_history = False >> self.last_index = 0 >> - return super().keypress(size, key) >> + return super().keypress(size, key) # type: ignore >> > > try using cast(Optional[str], super().keypress(size, key)) instead of the > type: ignore. It doesn't make a gigantic difference, really, but it looks > "narrower" in scope and will probably confuse *me* less in the future. > Fixed > > >> return None >> >> >> @@ -231,7 +238,7 @@ class EditorWidget(urwid.Filler): >> """ >> Wraps CustomEdit >> """ >> - def __init__(self, master): >> + def __init__(self, master: App) -> None: >> super().__init__(Editor(master), valign='top') >> >> >> @@ -239,12 +246,12 @@ class HistoryBox(urwid.ListBox): >> """ >> Shows all the QMP message transmitted/received >> """ >> - def __init__(self, master): >> + def __init__(self, master: App) -> None: >> self.master = master >> self.history = urwid.SimpleFocusListWalker([]) >> super().__init__(self.history) >> >> - def add_to_history(self, history): >> + def add_to_history(self, history: str) -> None: >> self.history.append(urwid.Text(history)) >> if self.history: >> self.history.set_focus(len(self.history) - 1) >> @@ -254,7 +261,7 @@ class HistoryWindow(urwid.Frame): >> """ >> Composes the HistoryBox and EditorWidget >> """ >> - def __init__(self, master): >> + def __init__(self, master: App) -> None: >> self.master = master >> self.editor_widget = EditorWidget(master) >> self.editor = urwid.LineBox(self.editor_widget) >> @@ -264,7 +271,7 @@ def __init__(self, master): >> super().__init__(self.body) >> urwid.connect_signal(self.master, UPDATE_MSG, >> self.cb_add_to_history) >> >> - def cb_add_to_history(self, msg): >> + def cb_add_to_history(self, msg: str) -> None: >> self.history.add_to_history(msg) >> >> >> @@ -275,7 +282,7 @@ class Window(urwid.Frame): >> future when we will have multiple windows and want to the switch >> between >> them and display overlays >> """ >> - def __init__(self, master): >> + def __init__(self, master: App) -> None: >> self.master = master >> footer = StatusBar() >> body = HistoryWindow(master) >> @@ -283,18 +290,18 @@ def __init__(self, master): >> >> >> class TUILogHandler(Handler): >> - def __init__(self, tui): >> + def __init__(self, tui: App) -> None: >> super().__init__() >> self.tui = tui >> >> - def emit(self, record): >> + def emit(self, record: LogRecord) -> None: >> level = record.levelname >> msg = record.getMessage() >> msg = f'[{level}]: {msg}' >> self.tui.add_to_history(msg) >> >> >> -def main(): >> +def main() -> None: >> parser = argparse.ArgumentParser(description='AQMP TUI') >> parser.add_argument('qmp_server', help='Address of the QMP server' >> '< UNIX socket path | TCP addr:port >') >> @@ -311,7 +318,7 @@ def main(): >> try: >> address = QEMUMonitorProtocol.parse_address(args.qmp_server) >> except QMPBadPortError as err: >> - parser.error(err) >> + parser.error(str(err)) >> >> app = App(address) >> >> @@ -330,4 +337,4 @@ def main(): >> >> >> if __name__ == '__main__': >> - main() # type: ignore >> + main() >> diff --git a/python/setup.cfg b/python/setup.cfg >> index 8cd9ac0d81..11c6240aba 100644 >> --- a/python/setup.cfg >> +++ b/python/setup.cfg >> @@ -83,9 +83,6 @@ namespace_packages = True >> allow_subclassing_any = True >> >> [mypy-qemu.aqmp.aqmp_tui] >> -disallow_untyped_defs = False >> -disallow_incomplete_defs = False >> -check_untyped_defs = False >> # urwid and urwid_readline have no type stubs: >> allow_subclassing_any = True >> >> -- >> 2.17.1 >> >> > Please squash this into the first patch, but it looks good, thanks! > Thanks. > > --js > --0000000000001243fe05c9379ed4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Aug 6, 2021 at 1:26 AM John Snow <jsnow@redhat.com> wr= ote:


On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu= <niteesh.gs@g= mail.com> wrote:
This patch adds type annotations for aqmp-tui using
the mypy library.


Awesome, thanks for taking a swing at = this. Looks like it wasn't as bad as I was fearing.
=C2= =A0
Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
---
=C2=A0python/qemu/aqmp/aqmp_tui.py | 79 ++++++++++++++++++++---------------= -
=C2=A0python/setup.cfg=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2= =A0 3 --
=C2=A02 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/python/qemu/aqmp/aqmp_tui.py b/python/qemu/aqmp/aqmp_tui.py index ec9eba0aa7..ab9ada793a 100644
--- a/python/qemu/aqmp/aqmp_tui.py
+++ b/python/qemu/aqmp/aqmp_tui.py
@@ -9,8 +9,15 @@
=C2=A0import argparse
=C2=A0import asyncio
=C2=A0import logging
-from logging import Handler
+from logging import Handler, LogRecord
=C2=A0import signal
+from typing import (
+=C2=A0 =C2=A0 Any,
+=C2=A0 =C2=A0 List,
+=C2=A0 =C2=A0 Optional,
+=C2=A0 =C2=A0 Tuple,
+=C2=A0 =C2=A0 Union,
+)

=C2=A0import urwid
=C2=A0import urwid_readline
@@ -22,13 +29,13 @@
=C2=A0from .util import create_task, pretty_traceback


-UPDATE_MSG =3D 'UPDATE_MSG'
+UPDATE_MSG: str =3D 'UPDATE_MSG'

=C2=A0# Using root logger to enable all loggers under qemu and asyncio
=C2=A0LOGGER =3D logging.getLogger()


-def format_json(msg):
+def format_json(msg: str) -> str:
=C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0Formats given multiline JSON message into a single line= message.
=C2=A0 =C2=A0 =C2=A0Converting into single line is more asthetically pleasi= ng when looking
@@ -43,17 +50,17 @@ def format_json(msg):


=C2=A0class App(QMPClient):
-=C2=A0 =C2=A0 def __init__(self, address):
+=C2=A0 =C2=A0 def __init__(self, address: Union[str, Tuple[str, int]]) -&g= t; None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0urwid.register_signal(type(self), UPDATE_= MSG)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.window =3D Window(self)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.address =3D address
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.aloop =3D None
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.aloop: Optional[Any] =3D None=C2=A0 # FIX= ME: Use more concrete type.

I ran into = this in util.py; you want Optional[asyncio.AbstractEventLoop] here.
Thanks. Fixed.=C2=A0
=C2= =A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__()

-=C2=A0 =C2=A0 def add_to_history(self, msg):
+=C2=A0 =C2=A0 def add_to_history(self, msg: str) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0urwid.emit_signal(self, UPDATE_MSG, msg)<= br>
-=C2=A0 =C2=A0 def _cb_outbound(self, msg):
+=C2=A0 =C2=A0 def _cb_outbound(self, msg: Message) -> Message:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# FIXME: I think the ideal way to omit th= ese messages during in-TUI
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# logging will be to add a filter to the = logger. We can use regex to
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# filter out messages starting with '= Request:' or 'Response:' but I
@@ -67,25 +74,25 @@ def _cb_outbound(self, msg):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.add_to_history('<-- ' + s= tr(msg))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return msg

-=C2=A0 =C2=A0 def _cb_inbound(self, msg):
+=C2=A0 =C2=A0 def _cb_inbound(self, msg: Message) -> Message:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0handler =3D LOGGER.handlers[0]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if not isinstance(handler, TUILogHandler)= :
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LOGGER.debug('Response:= %s', str(msg))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.add_to_history('--> ' + s= tr(msg))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return msg

-=C2=A0 =C2=A0 async def wait_for_events(self):
+=C2=A0 =C2=A0 async def wait_for_events(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0async for event in self.events:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.handle_event(event)
-=C2=A0 =C2=A0 async def _send_to_server(self, raw_msg):
+=C2=A0 =C2=A0 async def _send_to_server(self, raw_msg: str) -> None: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# FIXME: Format the raw_msg in history vi= ew to one line. It is not
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# pleasing to see multiple lines JSON obj= ect with an error statement.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0try:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0msg =3D Message(bytes(raw_m= sg, encoding=3D'utf-8'))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# Format multiline json int= o a single line JSON, since it is more
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# pleasing to look along wi= th err message in TUI.
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 raw_msg =3D self.format_json(raw= _msg)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 raw_msg =3D format_json(raw_msg)=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0await self._raw(msg, assign= _id=3D'id' not in msg)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0except (ValueError, TypeError) as err: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LOGGER.info('Invalid me= ssage: %s', str(err))
@@ -102,18 +109,18 @@ def _cb_inbound(self, msg):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LOGGER.error('Exception= from _send_to_server: %s', str(err))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0raise err

-=C2=A0 =C2=A0 def cb_send_to_server(self, msg):
+=C2=A0 =C2=A0 def cb_send_to_server(self, msg: str) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0create_task(self._send_to_server(msg))
-=C2=A0 =C2=A0 def unhandled_input(self, key):
+=C2=A0 =C2=A0 def unhandled_input(self, key: str) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if key =3D=3D 'esc':
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.kill_app()

-=C2=A0 =C2=A0 def kill_app(self):
+=C2=A0 =C2=A0 def kill_app(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# TODO: Work on the disconnect logic
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0create_task(self._kill_app())

-=C2=A0 =C2=A0 async def _kill_app(self):
+=C2=A0 =C2=A0 async def _kill_app(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# It is ok to call disconnect even in dis= connect state
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0try:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0await self.disconnect()
@@ -124,7 +131,7 @@ def kill_app(self):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0raise err
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0raise urwid.ExitMainLoop()

-=C2=A0 =C2=A0 def handle_event(self, event):
+=C2=A0 =C2=A0 def handle_event(self, event: Message) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# FIXME: Consider all states present in q= api/run-state.json
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if event['event'] =3D=3D 'SHU= TDOWN':
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._set_status('Serve= r shutdown')
@@ -139,7 +146,7 @@ def _get_formatted_address(self) -> str:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0addr =3D f'{host}:{port= }'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return addr

-=C2=A0 =C2=A0 async def connect_server(self):
+=C2=A0 =C2=A0 async def connect_server(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0try:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0await self.connect(self.add= ress)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0addr =3D self._get_formatte= d_address()
@@ -148,7 +155,7 @@ def _get_formatted_address(self) -> str:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LOGGER.info('connect_se= rver: ConnectError %s', str(err))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._set_status('Serve= r shutdown')

-=C2=A0 =C2=A0 def run(self, debug=3DFalse):
+=C2=A0 =C2=A0 def run(self, debug: bool =3D False) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.aloop =3D asyncio.get_event_loop() =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.aloop.set_debug(debug)

@@ -176,7 +183,7 @@ class StatusBar(urwid.Text):
=C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0A simple Text widget that currently only shows connecti= on status.
=C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 def __init__(self, text=3D''):
+=C2=A0 =C2=A0 def __init__(self, text: str =3D ''):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(text, align=3D'right= ')


@@ -185,14 +192,14 @@ class Editor(urwid_readline.ReadlineEdit):
=C2=A0 =C2=A0 =C2=A0Support urwid_readline features along with
=C2=A0 =C2=A0 =C2=A0history support which lacks in urwid_readline
=C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 def __init__(self, master):
+=C2=A0 =C2=A0 def __init__(self, master: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(caption=3D'> '= ;, multiline=3DTrue)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.master =3D master
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.history =3D []
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.last_index =3D -1
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.show_history =3D False
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.history: List[str] =3D []
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.last_index: int =3D -1
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.show_history: bool =3D False

-=C2=A0 =C2=A0 def keypress(self, size, key):
+=C2=A0 =C2=A0 def keypress(self, size: Tuple[int, int], key: str) -> Op= tional[str]:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# TODO: Add some logic for down key and c= lean up logic if possible.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# Returning None means the key has been h= andled by this widget
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# which otherwise is propogated to the pa= rent widget to be
@@ -223,7 +230,7 @@ def keypress(self, size, key):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.show_history =3D False=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.last_index =3D 0
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return super().keypress(size, ke= y)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return super().keypress(size, ke= y)=C2=A0 # type: ignore

try using cast(= Optional[str], super().keypress(size, key)) instead of the type: ignore. It= doesn't make a gigantic difference, really, but it looks "narrowe= r" in scope and will probably confuse *me* less in the future.
Fixed=C2=A0
=C2= =A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return None


@@ -231,7 +238,7 @@ class EditorWidget(urwid.Filler):
=C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0Wraps CustomEdit
=C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 def __init__(self, master):
+=C2=A0 =C2=A0 def __init__(self, master: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(Editor(master), valign= =3D'top')


@@ -239,12 +246,12 @@ class HistoryBox(urwid.ListBox):
=C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0Shows all the QMP message transmitted/received
=C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 def __init__(self, master):
+=C2=A0 =C2=A0 def __init__(self, master: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.master =3D master
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.history =3D urwid.SimpleFocusListWal= ker([])
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(self.history)

-=C2=A0 =C2=A0 def add_to_history(self, history):
+=C2=A0 =C2=A0 def add_to_history(self, history: str) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.history.append(urwid.Text(history))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if self.history:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.history.set_focus(len(= self.history) - 1)
@@ -254,7 +261,7 @@ class HistoryWindow(urwid.Frame):
=C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0Composes the HistoryBox and EditorWidget
=C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 def __init__(self, master):
+=C2=A0 =C2=A0 def __init__(self, master: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.master =3D master
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.editor_widget =3D EditorWidget(maste= r)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.editor =3D urwid.LineBox(self.editor= _widget)
@@ -264,7 +271,7 @@ def __init__(self, master):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(self.body)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0urwid.connect_signal(self.master, UPDATE_= MSG, self.cb_add_to_history)

-=C2=A0 =C2=A0 def cb_add_to_history(self, msg):
+=C2=A0 =C2=A0 def cb_add_to_history(self, msg: str) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.history.add_to_history(msg)


@@ -275,7 +282,7 @@ class Window(urwid.Frame):
=C2=A0 =C2=A0 =C2=A0future when we will have multiple windows and want to t= he switch between
=C2=A0 =C2=A0 =C2=A0them and display overlays
=C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 def __init__(self, master):
+=C2=A0 =C2=A0 def __init__(self, master: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.master =3D master
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0footer =3D StatusBar()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0body =3D HistoryWindow(master)
@@ -283,18 +290,18 @@ def __init__(self, master):


=C2=A0class TUILogHandler(Handler):
-=C2=A0 =C2=A0 def __init__(self, tui):
+=C2=A0 =C2=A0 def __init__(self, tui: App) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.tui =3D tui

-=C2=A0 =C2=A0 def emit(self, record):
+=C2=A0 =C2=A0 def emit(self, record: LogRecord) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0level =3D record.levelname
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0msg =3D record.getMessage()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0msg =3D f'[{level}]: {msg}'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.tui.add_to_history(msg)


-def main():
+def main() -> None:
=C2=A0 =C2=A0 =C2=A0parser =3D argparse.ArgumentParser(description=3D'A= QMP TUI')
=C2=A0 =C2=A0 =C2=A0parser.add_argument('qmp_server', help=3D'A= ddress of the QMP server'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0'< UNIX socket path | TCP addr:port >')
@@ -311,7 +318,7 @@ def main():
=C2=A0 =C2=A0 =C2=A0try:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0address =3D QEMUMonitorProtocol.parse_add= ress(args.qmp_server)
=C2=A0 =C2=A0 =C2=A0except QMPBadPortError as err:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 parser.error(err)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 parser.error(str(err))

=C2=A0 =C2=A0 =C2=A0app =3D App(address)

@@ -330,4 +337,4 @@ def main():


=C2=A0if __name__ =3D=3D '__main__':
-=C2=A0 =C2=A0 main()=C2=A0 # type: ignore
+=C2=A0 =C2=A0 main()
diff --git a/python/setup.cfg b/python/setup.cfg
index 8cd9ac0d81..11c6240aba 100644
--- a/python/setup.cfg
+++ b/python/setup.cfg
@@ -83,9 +83,6 @@ namespace_packages =3D True
=C2=A0allow_subclassing_any =3D True

=C2=A0[mypy-qemu.aqmp.aqmp_tui]
-disallow_untyped_defs =3D False
-disallow_incomplete_defs =3D False
-check_untyped_defs =3D False
=C2=A0# urwid and urwid_readline have no type stubs:
=C2=A0allow_subclassing_any =3D True

--
2.17.1


Please squash this into the first patch, but it looks goo= d, thanks!
Thanks.=C2=A0

--js
--0000000000001243fe05c9379ed4--