Skip to content

Commit 5c4e103

Browse files
author
anon
committed
Cleanup dynamic types
1 parent e0431a8 commit 5c4e103

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

qubesadmin/app.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import typing
3535
from logging import Logger
3636
from subprocess import Popen
37-
from typing import IO
37+
from typing import IO, TypeVar, Literal
3838
from collections.abc import Generator, Iterable
3939

4040
import qubesadmin.base
@@ -56,7 +56,9 @@
5656
except ImportError:
5757
has_qubesdb = False
5858

59-
DeviceClass = typing.LiteralString
59+
# ["mic", "block", "pci", "usb", "webcam"]
60+
# but can be extended
61+
DeviceClass = str
6062

6163

6264
class VMCollection:
@@ -222,9 +224,7 @@ def list_vmclass(self) -> list[Klass]:
222224
vmclass = (
223225
self.qubesd_call("dom0", "admin.vmclass.List").decode().splitlines()
224226
)
225-
for e in vmclass:
226-
assert e in typing.get_args(Klass)
227-
return typing.cast(list[Klass], sorted(vmclass))
227+
return sorted(vmclass)
228228

229229
def list_deviceclass(self) -> list[DeviceClass]:
230230
"""Call Qubesd in order to obtain the device classes list"""
@@ -233,10 +233,8 @@ def list_deviceclass(self) -> list[DeviceClass]:
233233
.decode()
234234
.splitlines()
235235
)
236-
for e in deviceclasses:
237-
assert e in typing.get_args(DeviceClass)
238236

239-
return typing.cast(list[DeviceClass], sorted(deviceclasses))
237+
return sorted(deviceclasses)
240238

241239
def _refresh_pool_drivers(self) -> None:
242240
"""

qubesadmin/vm/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import typing
2828
import warnings
2929
from logging import Logger
30-
from typing import Literal
30+
from typing import Literal, TypeVar
3131

3232
import qubesadmin.exc
3333
import qubesadmin.storage
@@ -39,7 +39,10 @@
3939
if typing.TYPE_CHECKING:
4040
import qubesadmin.base
4141

42-
Klass = Literal["AppVM", "AdminVM", "TemplateVM", "DispVM", "StandaloneVM"]
42+
43+
# ["AppVM", "AdminVM", "TemplateVM", "DispVM", "StandaloneVM"]
44+
# but can be extended
45+
Klass = str
4346
PowerState = Literal["Transient", "Running", "Halted", "Paused",
4447
"Suspended", "Halting", "Dying", "Crashed", "NA"]
4548

0 commit comments

Comments
 (0)