@@ -13,6 +13,7 @@
import logging
from typing import (
Any,
+ cast,
Dict,
Optional,
TextIO,
@@ -130,7 +131,10 @@ def __json_read(self, only_event=False):
data = self.__sockfile.readline()
if not data:
return None
- resp = json.loads(data)
+ # By definition, any JSON received from QMP is a QMPMessage,
+ # and we are asserting only at static analysis time that it
+ # has a particular shape.
+ resp: QMPMessage = json.loads(data)
if 'event' in resp:
self.logger.debug("<<< %s", resp)
self.__events.append(resp)
@@ -262,7 +266,7 @@ def command(self, cmd, **kwds):
ret = self.cmd(cmd, kwds)
if 'error' in ret:
raise QMPResponseError(ret)
- return ret['return']
+ return cast(QMPReturnValue, ret['return'])
def pull_event(self, wait=False):
"""