[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH RFC 26/32] python//machine.py: use qmp.command
From: |
John Snow |
Subject: |
Re: [PATCH RFC 26/32] python//machine.py: use qmp.command |
Date: |
Thu, 28 May 2020 20:18:28 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
[...]
>
> - 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
- Re: [PATCH RFC 20/32] python//qmp.py: assert sockfile is not None, (continued)
- [PATCH RFC 21/32] python//machine.py: remove logging configuration, John Snow, 2020/05/14
- [PATCH RFC 22/32] python//machine.py: Fix monitor address typing, John Snow, 2020/05/14
- [PATCH RFC 23/32] python//machine.py: reorder __init__, John Snow, 2020/05/14
- [PATCH RFC 24/32] python//machine.py: Don't modify state in _base_args(), John Snow, 2020/05/14
- [PATCH RFC 25/32] python//machine.py: Handle None events in event_wait, John Snow, 2020/05/14
- [PATCH RFC 26/32] python//machine.py: use qmp.command, John Snow, 2020/05/14
- Re: [PATCH RFC 26/32] python//machine.py: use qmp.command,
John Snow <=
- [PATCH RFC 28/32] python//machine.py: fix _popen access, John Snow, 2020/05/14
- [PATCH RFC 27/32] python//machine.py: Add _qmp access shim, John Snow, 2020/05/14
- [PATCH RFC 29/32] python//qtest.py: Check before accessing _qtest, John Snow, 2020/05/14
- [PATCH RFC 12/32] python/qemu/lib: fix socket.makefile() typing, John Snow, 2020/05/14
- [PATCH RFC 31/32] python/qemu: add mypy to Pipfile, John Snow, 2020/05/14
- [PATCH RFC 19/32] python//qmp.py: add QMPProtocolError, John Snow, 2020/05/14