qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

iotests: touch up log function signature

Representing nested, recursive data structures in mypy is notoriously
difficult; the best we can reliably do right now is denote the leaf
types as "Any" while describing the general shape of the data.

Regardless, this fully annotates the log() function.

Typing notes:

TypeVar is a Type variable that can optionally be constrained by a
sequence of possible types. This variable is bound to a specific type
per-invocation, like a Generic.

log() behaves as log<Msg>() now, where the incoming type informs the
signature it expects for any filter arguments passed in. If Msg is a
str, then filter should take and return a str.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200331000014.11581-9-jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>

authored by

John Snow and committed by
Max Reitz
1cd0dbfc 229fc074

+11 -3
+11 -3
tests/qemu-iotests/iotests.py
··· 28 28 import struct 29 29 import subprocess 30 30 import sys 31 + from typing import (Any, Callable, Dict, Iterable, List, Optional, TypeVar) 31 32 import unittest 32 33 33 34 # pylint: disable=import-error, wrong-import-position ··· 354 355 return value 355 356 return filter_qmp(qmsg, _filter) 356 357 357 - def log(msg, filters=(), indent=None): 358 - '''Logs either a string message or a JSON serializable message (like QMP). 359 - If indent is provided, JSON serializable messages are pretty-printed.''' 358 + 359 + Msg = TypeVar('Msg', Dict[str, Any], List[Any], str) 360 + 361 + def log(msg: Msg, 362 + filters: Iterable[Callable[[Msg], Msg]] = (), 363 + indent: Optional[int] = None) -> None: 364 + """ 365 + Logs either a string message or a JSON serializable message (like QMP). 366 + If indent is provided, JSON serializable messages are pretty-printed. 367 + """ 360 368 for flt in filters: 361 369 msg = flt(msg) 362 370 if isinstance(msg, (dict, list)):