diff options
author | Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 2021-08-24 11:38:47 +0300 |
---|---|---|
committer | Hanna Reitz <hreitz@redhat.com> | 2021-09-01 14:03:47 +0200 |
commit | 15c3b863ee6393fa326c142b725cff88bb3e719e (patch) | |
tree | 0a955c26e8d739049e8656067d320518595773d3 | |
parent | 3f3c9b4c9dcb462b2330e50cf81b9703288884ec (diff) | |
download | qemu-15c3b863ee6393fa326c142b725cff88bb3e719e.zip qemu-15c3b863ee6393fa326c142b725cff88bb3e719e.tar.gz qemu-15c3b863ee6393fa326c142b725cff88bb3e719e.tar.bz2 |
python:QEMUMachine: template typing for self returning methods
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>
-rw-r--r-- | python/qemu/machine/machine.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py index 6ec1857..a7081b1 100644 --- a/python/qemu/machine/machine.py +++ b/python/qemu/machine/machine.py @@ -36,6 +36,7 @@ from typing import ( 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 @@ class QEMUMachine: 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 @@ class QEMUMachine: 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 """ |