[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 54/72] scripts/qmp-shell: refactor QMPCompleter
From: |
John Snow |
Subject: |
[PULL 54/72] scripts/qmp-shell: refactor QMPCompleter |
Date: |
Fri, 18 Jun 2021 19:04:37 -0400 |
list is a generic type, but we expect to use strings directly. We could
subclass list[str], but pylint does not presently understand that
invocation.
Change this class to envelop a list instead of *being* a list, for
simpler mypy typing.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 20210607200649.1840382-25-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qmp/qmp-shell | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index 847d34890f..73694035b2 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -78,9 +78,17 @@ sys.path.append(os.path.join(os.path.dirname(__file__),
'..', '..', 'python'))
from qemu import qmp
-class QMPCompleter(list):
- def complete(self, text, state):
- for cmd in self:
+class QMPCompleter:
+ # NB: Python 3.9+ will probably allow us to subclass list[str] directly,
+ # but pylint as of today does not know that List[str] is simply 'list'.
+ def __init__(self) -> None:
+ self._matches: List[str] = []
+
+ def append(self, value: str) -> None:
+ return self._matches.append(value)
+
+ def complete(self, text: str, state: int) -> Optional[str]:
+ for cmd in self._matches:
if cmd.startswith(text):
if state == 0:
return cmd
--
2.31.1
- [PULL 40/72] scripts/qmp-shell: use triple-double-quote docstring style, (continued)
- [PULL 40/72] scripts/qmp-shell: use triple-double-quote docstring style, John Snow, 2021/06/18
- [PULL 41/72] scripts/qmp-shell: ignore visit_Name name, John Snow, 2021/06/18
- [PULL 42/72] scripts/qmp-shell: make QMPCompleter returns explicit, John Snow, 2021/06/18
- [PULL 50/72] scripts/qmp-shell: move get_prompt() to prompt property, John Snow, 2021/06/18
- [PULL 23/72] scripts/qemu-ga-client: replace deprecated optparse with argparse, John Snow, 2021/06/18
- [PULL 25/72] scripts/qemu-ga-client: apply (most) pylint rules, John Snow, 2021/06/18
- [PULL 24/72] scripts/qemu-ga-client: add module docstring, John Snow, 2021/06/18
- [PULL 34/72] scripts/qmp-shell: fix exception handling, John Snow, 2021/06/18
- [PULL 51/72] scripts/qmp-shell: remove prompt argument from read_exec_command, John Snow, 2021/06/18
- [PULL 53/72] scripts/qmp-shell: Fix "FuzzyJSON" parser, John Snow, 2021/06/18
- [PULL 54/72] scripts/qmp-shell: refactor QMPCompleter,
John Snow <=
- [PULL 52/72] scripts/qmp-shell: move the REPL functionality into QMPShell, John Snow, 2021/06/18
- [PULL 47/72] scripts/qmp-shell: use argparse, John Snow, 2021/06/18
- [PULL 45/72] scripts/qmp-shell: remove if-raise-else patterns, John Snow, 2021/06/18
- [PULL 55/72] scripts/qmp-shell: initialize completer early, John Snow, 2021/06/18
- [PULL 56/72] python/qmp: add QMPObject type alias, John Snow, 2021/06/18
- [PULL 57/72] scripts/qmp-shell: add mypy types, John Snow, 2021/06/18
- [PULL 59/72] scripts/qmp-shell: unprivatize 'pretty' property, John Snow, 2021/06/18
- [PULL 60/72] python/qmp: return generic type from context manager, John Snow, 2021/06/18
- [PULL 64/72] scripts/qmp-shell: Fix empty-transaction invocation, John Snow, 2021/06/18
- [PULL 63/72] scripts/qmp-shell: remove TODO, John Snow, 2021/06/18