Skip to content

Commit 143aa64

Browse files
author
anon
committed
misc. typing fixes
1 parent 9925635 commit 143aa64

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

qubesadmin/app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@ def get_blind(self, item: str) -> QubesVM:
148148

149149
T = TypeVar("T")
150150

151-
def get(self, item: str | QubesVM, default: QubesVM | T=None)\
152-
-> QubesVM | T:
151+
@typing.overload
152+
def get(self, item: str | QubesVM) -> QubesVM:
153+
...
154+
@typing.overload
155+
def get(self, item: str | QubesVM, default: T) -> QubesVM | T:
156+
...
157+
# Overloaded to handle default None return type
158+
def get(self, item: str | QubesVM, default: object=None)\
159+
-> object:
153160
"""
154161
Get a VM object, or return *default* if it can't be found.
155162
"""

qubesadmin/backup/core2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def rule_from_xml_v1(node: _Element, action: str) -> Rule:
8787

8888
expire = node.get('expire')
8989

90-
kwargs = {
90+
kwargs: dict[str, object] = {
9191
'action': action,
9292
}
9393
if dsthost:

qubesadmin/backup/restore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ def _process_qubes_xml(self) -> Core2Qubes | Core3Qubes:
14381438
queue.put(QUEUE_FINISHED)
14391439

14401440
qubes_xml_path = os.path.join(self.tmpdir, 'qubes-restored.xml')
1441-
handlers = {
1441+
handlers: dict[str, Callable] = {
14421442
'qubes.xml': functools.partial(self._save_qubes_xml, qubes_xml_path)
14431443
}
14441444
extract_proc = self._start_inner_extraction_worker(queue, handlers)

qubesadmin/device_protocol.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ def __lt__(self, other: object) -> bool:
513513
other.port, AnyPort
514514
):
515515
return False
516-
reprs = {self: [self.port], other: [other.port]}
516+
reprs: dict[VirtualDevice | DeviceAssignment, list[Port | str]] \
517+
= {self: [self.port], other: [other.port]}
517518
for obj, obj_repr in reprs.items():
518519
if obj.device_id != "*":
519520
obj_repr.append(obj.device_id)

qubesadmin/storage.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def __lt__(self, other: object) -> bool:
111111
if self._vm and other._vm:
112112
assert self._vm_name is not None and other._vm_name is not None
113113
return (self._vm, self._vm_name) < (other._vm, other._vm_name)
114-
if self._vid and other._vid:
115-
assert self._pool is not None and other._pool is not None
114+
if self._pool and other._pool:
115+
assert self._vid is not None and other._vid is not None
116116
return (self._pool, self._vid) < (other._pool, other._vid)
117117
return NotImplemented
118118

@@ -279,8 +279,6 @@ def revert(self, revision: str) -> None:
279279
280280
:param str revision: Revision identifier to revert to
281281
"""
282-
if not isinstance(revision, str):
283-
raise TypeError('revision must be a str')
284282
self._qubesd_call('Revert', revision.encode('ascii'))
285283

286284
def import_data(self, stream: BinaryIO) -> None:
@@ -332,7 +330,7 @@ class Pool:
332330
""" A Pool is used to manage different kind of volumes (File
333331
based/LVM/Btrfs/...).
334332
"""
335-
def __init__(self, app: QubesBase, name: str | None=None):
333+
def __init__(self, app: QubesBase, name: str):
336334
""" Initialize storage pool wrapper
337335
338336
:param app: Qubes() object
@@ -343,7 +341,6 @@ def __init__(self, app: QubesBase, name: str | None=None):
343341
self._config = None
344342

345343
def __str__(self) -> str:
346-
assert self.name is not None
347344
return self.name
348345

349346
def __eq__(self, other: object) -> bool:

0 commit comments

Comments
 (0)