[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 25/34] python:QEMUMachine: template typing for self returning
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v8 25/34] python:QEMUMachine: template typing for self returning methods |
Date: |
Tue, 24 Aug 2021 11:38:47 +0300 |
mypy thinks that return value of these methods in subclusses is
QEMUMachine, which is wrong. So, make typing smarter.
Suggested-by: John Snow <jsnow@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
python/qemu/machine/machine.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
index ce1e130c13..1c347d2c30 100644
--- a/python/qemu/machine/machine.py
+++ b/python/qemu/machine/machine.py
@@ -36,6 +36,7 @@
Sequence,
Tuple,
Type,
+ TypeVar,
)
from qemu.qmp import ( # pylint: disable=import-error
@@ -73,6 +74,9 @@ class AbnormalShutdown(QEMUMachineError):
"""
+_T = TypeVar('_T', bound='QEMUMachine')
+
+
class QEMUMachine:
"""
A QEMU VM.
@@ -166,7 +170,7 @@ def __init__(self,
self._remove_files: List[str] = []
self._user_killed = False
- def __enter__(self) -> 'QEMUMachine':
+ def __enter__(self: _T) -> _T:
return self
def __exit__(self,
@@ -182,8 +186,8 @@ def add_monitor_null(self) -> None:
self._args.append('-monitor')
self._args.append('null')
- def add_fd(self, fd: int, fdset: int,
- opaque: str, opts: str = '') -> 'QEMUMachine':
+ def add_fd(self: _T, fd: int, fdset: int,
+ opaque: str, opts: str = '') -> _T:
"""
Pass a file descriptor to the VM
"""
--
2.29.2
- [PATCH v8 02/34] block: introduce blk_replace_bs, (continued)
- [PATCH v8 02/34] block: introduce blk_replace_bs, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 05/34] block: rename backup-top to copy-before-write, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 14/34] block/copy-before-write: introduce cbw_init(), Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 11/34] block/copy-before-write: drop extra bdrv_unref on failure path, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 16/34] block/copy-before-write: cbw_init(): use file child after attaching, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 10/34] block/copy-before-write: relax permission requirements when no parents, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 18/34] block/copy-before-write: cbw_init(): use options, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 12/34] block/copy-before-write: use file child instead of backing, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 09/34] block/backup: move cluster size calculation to block-copy, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 15/34] block/copy-before-write: cbw_init(): rename variables, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 25/34] python:QEMUMachine: template typing for self returning methods,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v8 22/34] qapi: publish copy-before-write filter, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 26/34] iotests/222: fix pylint and mypy complains, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 13/34] block/copy-before-write: bdrv_cbw_append(): replace child at last, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 21/34] block/copy-before-write: make public block driver, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 17/34] block/copy-before-write: bdrv_cbw_append(): drop unused compress arg, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 19/34] block/copy-before-write: initialize block-copy bitmap, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 20/34] block/block-copy: make setting progress optional, Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 23/34] python/qemu/machine.py: refactor _qemu_args(), Vladimir Sementsov-Ogievskiy, 2021/08/24
- [PATCH v8 24/34] python/qemu/machine: QEMUMachine: improve qmp() method, Vladimir Sementsov-Ogievskiy, 2021/08/24