mirror of https://github.com/xemu-project/xemu.git
scripts/qmp-shell: refactor QMPCompleter
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>
This commit is contained in:
parent
6faf2384ec
commit
db12abc208
|
@ -78,9 +78,17 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
|
||||||
from qemu import qmp
|
from qemu import qmp
|
||||||
|
|
||||||
|
|
||||||
class QMPCompleter(list):
|
class QMPCompleter:
|
||||||
def complete(self, text, state):
|
# NB: Python 3.9+ will probably allow us to subclass list[str] directly,
|
||||||
for cmd in self:
|
# 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 cmd.startswith(text):
|
||||||
if state == 0:
|
if state == 0:
|
||||||
return cmd
|
return cmd
|
||||||
|
|
Loading…
Reference in New Issue