[...]
>
> - def qmp(self, cmd, conv_keys=True, **args):
> - """
> - Invoke a QMP command and return the response dict
> - """
> + @classmethod
> + def _qmp_args(cls, _conv_keys: bool = True, **args: Any) -> Dict[str,
> Any]:
> qmp_args = dict()
> for key, value in args.items():
> - if conv_keys:
> + if _conv_keys:
> qmp_args[key.replace('_', '-')] = value
> else:
> qmp_args[key] = value
> + return qmp_args
>
> + def qmp(self, cmd: str,
> + conv_keys: bool = True,
> + **args: Any) -> QMPMessage:
This creates an interesting problem with iotests 297:
-Success: no issues found in 1 source file
+iotests.py:563: error: Argument 2 to "qmp" of "QEMUMachine" has
incompatible type "**Dict[str, str]"; expected "bool"
+Found 1 error in 1 file (checked 1 source file)
def hmp(self, command_line: str, use_log: bool = False) -> QMPResponse:
cmd = 'human-monitor-command'
kwargs = {'command-line': command_line}
if use_log:
return self.qmp_log(cmd, **kwargs)
else:
return self.qmp(cmd, **kwargs)
It seems like mypy is unable to understand that we are passing keyword
arguments, and instead believes we're passing something to the conv_keys
parameter.
(Is this a bug...?)
Even amending the function signature to indicate that conv_keys should
only ever appear as a keyword argument doesn't seem to help.
I'll have to think about a nice way to fix this; removing conv_keys out
of the argument namespace seems like the best approach.
qmp(cmd, foo=bar, hello=world)
qmp(cmd, **conv_keys(foo=bar, hello=world))
...but now this function looks really annoying to call.
Uh, I'll play around with this, but let me know if you have any cool ideas.
--js