python/qemu: Adjust traceback typing
mypy considers it incorrect to use `bool` to statically return false, because it will assume that it could conceivably return True, and gives different analysis in that case. Use a None return to achieve the same effect, but make mypy happy. Note: Pylint considers function signatures as code that might trip the duplicate-code checker. I'd rather not disable this as it does not trigger often in practice, so I'm disabling it as a one-off and filed a change request; see https://github.com/PyCQA/pylint/issues/3619 Signed-off-by: John Snow <jsnow@redhat.com> Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200514055403.18902-14-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
This commit is contained in:
parent
0add048fbd
commit
1dda0404d8
|
@ -24,6 +24,8 @@ import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from typing import Optional, Type
|
||||||
|
from types import TracebackType
|
||||||
|
|
||||||
from . import qmp
|
from . import qmp
|
||||||
|
|
||||||
|
@ -124,9 +126,11 @@ class QEMUMachine:
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self,
|
||||||
|
exc_type: Optional[Type[BaseException]],
|
||||||
|
exc_val: Optional[BaseException],
|
||||||
|
exc_tb: Optional[TracebackType]) -> None:
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
return False
|
|
||||||
|
|
||||||
def add_monitor_null(self):
|
def add_monitor_null(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -14,7 +14,9 @@ import logging
|
||||||
from typing import (
|
from typing import (
|
||||||
Optional,
|
Optional,
|
||||||
TextIO,
|
TextIO,
|
||||||
|
Type,
|
||||||
)
|
)
|
||||||
|
from types import TracebackType
|
||||||
|
|
||||||
|
|
||||||
class QMPError(Exception):
|
class QMPError(Exception):
|
||||||
|
@ -146,10 +148,14 @@ class QEMUMonitorProtocol:
|
||||||
# Implement context manager enter function.
|
# Implement context manager enter function.
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
def __exit__(self,
|
||||||
|
# pylint: disable=duplicate-code
|
||||||
|
# see https://github.com/PyCQA/pylint/issues/3619
|
||||||
|
exc_type: Optional[Type[BaseException]],
|
||||||
|
exc_val: Optional[BaseException],
|
||||||
|
exc_tb: Optional[TracebackType]) -> None:
|
||||||
# Implement context manager exit function.
|
# Implement context manager exit function.
|
||||||
self.close()
|
self.close()
|
||||||
return False
|
|
||||||
|
|
||||||
def connect(self, negotiate=True):
|
def connect(self, negotiate=True):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue