[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 30/42] python/qmp: return generic type from context manager
From: |
John Snow |
Subject: |
[PATCH 30/42] python/qmp: return generic type from context manager |
Date: |
Mon, 7 Jun 2021 16:06:37 -0400 |
__enter__ can be invoked from a subclass, so it needs a more flexible
type.
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/qmp/__init__.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py
index ba0d2281d6..376954cb6d 100644
--- a/python/qemu/qmp/__init__.py
+++ b/python/qemu/qmp/__init__.py
@@ -30,6 +30,7 @@
TextIO,
Tuple,
Type,
+ TypeVar,
Union,
cast,
)
@@ -220,7 +221,9 @@ def __get_events(self, wait: Union[bool, float] = False) ->
None:
if ret is None:
raise QMPConnectError("Error while reading from socket")
- def __enter__(self) -> 'QEMUMonitorProtocol':
+ T = TypeVar('T')
+
+ def __enter__(self: T) -> T:
# Implement context manager enter function.
return self
--
2.31.1
- [PATCH 20/42] scripts/qmp-shell: move get_prompt() to prompt property, (continued)
- [PATCH 20/42] scripts/qmp-shell: move get_prompt() to prompt property, John Snow, 2021/06/07
- [PATCH 10/42] scripts/qmp-shell: use triple-double-quote docstring style, John Snow, 2021/06/07
- [PATCH 18/42] scripts/qmp-shell: Add pretty attribute to HMP shell, John Snow, 2021/06/07
- [PATCH 15/42] scripts/qmp-shell: remove if-raise-else patterns, John Snow, 2021/06/07
- [PATCH 29/42] scripts/qmp-shell: unprivatize 'pretty' property, John Snow, 2021/06/07
- [PATCH 19/42] scripts/qmp-shell: Make verbose a public attribute, John Snow, 2021/06/07
- [PATCH 25/42] scripts/qmp-shell: initialize completer early, John Snow, 2021/06/07
- [PATCH 27/42] scripts/qmp-shell: add mypy types, John Snow, 2021/06/07
- [PATCH 24/42] scripts/qmp-shell: refactor QMPCompleter, John Snow, 2021/06/07
- [PATCH 16/42] scripts/qmp-shell: use isinstance() instead of type(), John Snow, 2021/06/07
- [PATCH 30/42] python/qmp: return generic type from context manager,
John Snow <=
- [PATCH 33/42] scripts/qmp-shell: remove TODO, John Snow, 2021/06/07
- [PATCH 23/42] scripts/qmp-shell: Fix "FuzzyJSON" parser, John Snow, 2021/06/07
- [PATCH 35/42] scripts/qmp-shell: Remove too-broad-exception, John Snow, 2021/06/07
- [PATCH 26/42] python/qmp: add QMPObject type alias, John Snow, 2021/06/07
- [PATCH 13/42] scripts/qmp-shell: rename one and two-letter variables, John Snow, 2021/06/07
- [PATCH 28/42] scripts/qmp-shell: Accept SocketAddrT instead of string, John Snow, 2021/06/07
- [PATCH 22/42] scripts/qmp-shell: move the REPL functionality into QMPShell, John Snow, 2021/06/07
- [PATCH 32/42] scripts/qmp-shell: use logging to show warnings, John Snow, 2021/06/07
- [PATCH 34/42] scripts/qmp-shell: Fix empty-transaction invocation, John Snow, 2021/06/07
- [PATCH 31/42] scripts/qmp-shell: Use context manager instead of atexit, John Snow, 2021/06/07