[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/25] python/qemu: Adjust traceback typing
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 14/25] python/qemu: Adjust traceback typing |
Date: |
Sun, 31 May 2020 18:38:35 +0200 |
From: John Snow <jsnow@redhat.com>
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>
---
python/qemu/machine.py | 8 ++++++--
python/qemu/qmp.py | 10 ++++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 95a20a17f9..041c615052 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -24,6 +24,8 @@
import shutil
import socket
import tempfile
+from typing import Optional, Type
+from types import TracebackType
from . import qmp
@@ -124,9 +126,11 @@ def __init__(self, binary, args=None, wrapper=None,
name=None,
def __enter__(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()
- return False
def add_monitor_null(self):
"""
diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py
index 73d49050ed..b91c9d5c1c 100644
--- a/python/qemu/qmp.py
+++ b/python/qemu/qmp.py
@@ -14,7 +14,9 @@
from typing import (
Optional,
TextIO,
+ Type,
)
+from types import TracebackType
class QMPError(Exception):
@@ -146,10 +148,14 @@ def __enter__(self):
# Implement context manager enter function.
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.
self.close()
- return False
def connect(self, negotiate=True):
"""
--
2.21.3
- [PULL 04/25] scripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main(), (continued)
- [PULL 04/25] scripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main(), Philippe Mathieu-Daudé, 2020/05/31
- [PULL 05/25] scripts/modules/module_block: Use Python 3 interpreter & add pseudo-main, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 06/25] scripts/qmp: Fix shebang and imports, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 07/25] python: remove more instances of sys.version_info, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 08/25] python/qemu/machine: add kill() method, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 09/25] python/qemu/machine: remove logging configuration, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 10/25] python/qemu: delint and add pylintrc, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 11/25] python/qemu: delint; add flake8 config, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 12/25] python/qemu: remove Python2 style super() calls, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 13/25] python/qemu: fix socket.makefile() typing, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 14/25] python/qemu: Adjust traceback typing,
Philippe Mathieu-Daudé <=
- [PULL 15/25] python/qemu/qmp: use True/False for non/blocking modes, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 16/25] python/qemu/qmp: assert sockfile is not None, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 17/25] python/qemu/qtest: Check before accessing _qtest, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 18/25] tests/vm: Pass --debug through for vm-boot-ssh, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 19/25] tests/vm: Add ability to select QEMU from current build, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 20/25] tests/vm: allow wait_ssh() to specify command, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 21/25] tests/migration/guestperf: Use Python 3 interpreter, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 22/25] tests/acceptance/migration.py: Wait for both sides, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 23/25] tests/acceptance: allow console interaction with specific VMs, Philippe Mathieu-Daudé, 2020/05/31
- [PULL 24/25] tests/acceptance: refactor boot_linux_console test to allow code reuse, Philippe Mathieu-Daudé, 2020/05/31