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>
This commit is contained in:
parent
3f3c9b4c9d
commit
15c3b863ee
|
@ -36,6 +36,7 @@ from typing import (
|
||||||
Sequence,
|
Sequence,
|
||||||
Tuple,
|
Tuple,
|
||||||
Type,
|
Type,
|
||||||
|
TypeVar,
|
||||||
)
|
)
|
||||||
|
|
||||||
from qemu.qmp import ( # pylint: disable=import-error
|
from qemu.qmp import ( # pylint: disable=import-error
|
||||||
|
@ -73,6 +74,9 @@ class AbnormalShutdown(QEMUMachineError):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
_T = TypeVar('_T', bound='QEMUMachine')
|
||||||
|
|
||||||
|
|
||||||
class QEMUMachine:
|
class QEMUMachine:
|
||||||
"""
|
"""
|
||||||
A QEMU VM.
|
A QEMU VM.
|
||||||
|
@ -169,7 +173,7 @@ class QEMUMachine:
|
||||||
self._remove_files: List[str] = []
|
self._remove_files: List[str] = []
|
||||||
self._user_killed = False
|
self._user_killed = False
|
||||||
|
|
||||||
def __enter__(self) -> 'QEMUMachine':
|
def __enter__(self: _T) -> _T:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self,
|
def __exit__(self,
|
||||||
|
@ -185,8 +189,8 @@ class QEMUMachine:
|
||||||
self._args.append('-monitor')
|
self._args.append('-monitor')
|
||||||
self._args.append('null')
|
self._args.append('null')
|
||||||
|
|
||||||
def add_fd(self, fd: int, fdset: int,
|
def add_fd(self: _T, fd: int, fdset: int,
|
||||||
opaque: str, opts: str = '') -> 'QEMUMachine':
|
opaque: str, opts: str = '') -> _T:
|
||||||
"""
|
"""
|
||||||
Pass a file descriptor to the VM
|
Pass a file descriptor to the VM
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue