python/qemu: Add mypy type annotations

These should all be purely annotations with no changes in behavior at
all. You need to be in the python folder, but you should be able to
confirm that these annotations are correct (or at least self-consistent)
by running `mypy --strict qemu`.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 20201006235817.3280413-12-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
This commit is contained in:
John Snow
2020-10-06 19:58:08 -04:00
parent 090744d552
commit f12a282ff4
4 changed files with 101 additions and 75 deletions

View File

@ -17,6 +17,7 @@ accelerators.
import logging
import os
import subprocess
from typing import List, Optional
LOG = logging.getLogger(__name__)
@ -30,7 +31,7 @@ ADDITIONAL_ARCHES = {
}
def list_accel(qemu_bin):
def list_accel(qemu_bin: str) -> List[str]:
"""
List accelerators enabled in the QEMU binary.
@ -50,7 +51,8 @@ def list_accel(qemu_bin):
return [acc.strip() for acc in out.splitlines()[1:]]
def kvm_available(target_arch=None, qemu_bin=None):
def kvm_available(target_arch: Optional[str] = None,
qemu_bin: Optional[str] = None) -> bool:
"""
Check if KVM is available using the following heuristic:
- Kernel module is present in the host;
@ -73,7 +75,7 @@ def kvm_available(target_arch=None, qemu_bin=None):
return True
def tcg_available(qemu_bin):
def tcg_available(qemu_bin: str) -> bool:
"""
Check if TCG is available.