[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 45/56] python:QEMUMachine: template typing for self returning meth
From: |
Hanna Reitz |
Subject: |
[PULL 45/56] python:QEMUMachine: template typing for self returning methods |
Date: |
Wed, 1 Sep 2021 17:16:08 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
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>
Message-Id: <20210824083856.17408-26-vsementsov@virtuozzo.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.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 6ec18570d9..a7081b1845 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.
@@ -169,7 +173,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,
@@ -185,8 +189,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.31.1
- [PULL 37/56] block/copy-before-write: bdrv_cbw_append(): drop unused compress arg, (continued)
- [PULL 37/56] block/copy-before-write: bdrv_cbw_append(): drop unused compress arg, Hanna Reitz, 2021/09/01
- [PULL 35/56] block/copy-before-write: cbw_init(): rename variables, Hanna Reitz, 2021/09/01
- [PULL 39/56] block/copy-before-write: initialize block-copy bitmap, Hanna Reitz, 2021/09/01
- [PULL 40/56] block/block-copy: make setting progress optional, Hanna Reitz, 2021/09/01
- [PULL 41/56] block/copy-before-write: make public block driver, Hanna Reitz, 2021/09/01
- [PULL 43/56] python/qemu/machine.py: refactor _qemu_args(), Hanna Reitz, 2021/09/01
- [PULL 42/56] qapi: publish copy-before-write filter, Hanna Reitz, 2021/09/01
- [PULL 44/56] python/qemu/machine: QEMUMachine: improve qmp() method, Hanna Reitz, 2021/09/01
- [PULL 45/56] python:QEMUMachine: template typing for self returning methods,
Hanna Reitz <=
- [PULL 46/56] iotests/222: fix pylint and mypy complains, Hanna Reitz, 2021/09/01
- [PULL 47/56] iotests/222: constantly use single quotes for strings, Hanna Reitz, 2021/09/01
- [PULL 48/56] iotests: move 222 to tests/image-fleecing, Hanna Reitz, 2021/09/01
- [PULL 50/56] iotests/image-fleecing: proper source device, Hanna Reitz, 2021/09/01
- [PULL 49/56] iotests.py: hmp_qemu_io: support qdev, Hanna Reitz, 2021/09/01
- [PULL 52/56] iotests/image-fleecing: prepare for adding new test-case, Hanna Reitz, 2021/09/01
- [PULL 51/56] iotests/image-fleecing: rename tgt_node, Hanna Reitz, 2021/09/01
- [PULL 53/56] iotests/image-fleecing: add test-case for copy-before-write filter, Hanna Reitz, 2021/09/01
- [PULL 54/56] block/block-copy: block_copy_state_new(): drop extra arguments, Hanna Reitz, 2021/09/01
- [PULL 55/56] block/export/fuse.c: fix fuse-lseek on uclibc or musl, Hanna Reitz, 2021/09/01