Skip to content

Commit e6d9670

Browse files
committed
Merge branch 'propery-type'
* propery-type: tests: type preservation on stateless property Add type annotations to some stateless properties Preserve stateless property based on type annotation
2 parents be94b39 + 7279dbc commit e6d9670

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

qubes/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,13 @@ def bool(self, prop, value):
505505
def stateless_property(func):
506506
"""Decorator similar to :py:class:`builtins.property`, but for properties
507507
exposed through management API (including qvm-prefs etc)"""
508+
prop_type = func.__annotations__.get('return', None)
508509
return property(
509510
func.__name__,
510511
setter=property.forbidden,
511512
saver=property.dontsave,
512513
default=func,
514+
type=prop_type,
513515
doc=func.__doc__,
514516
)
515517

qubes/tests/api_admin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ def test_021_vm_property_get_int(self):
261261
b"admin.vm.property.Get", b"test-vm1", b"vcpus"
262262
)
263263
self.assertEqual(value, "default=True type=int 2")
264+
# check also if type is preserved on stateless property
265+
value = self.call_mgmt_func(
266+
b"admin.vm.property.Get", b"test-vm1", b"xid"
267+
)
268+
self.assertEqual(value, "default=True type=int -1")
264269

265270
def test_022_vm_property_get_bool(self):
266271
value = self.call_mgmt_func(

qubes/vm/qubesvm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def __str__(self):
950950
# VMM-related
951951

952952
@qubes.stateless_property
953-
def xid(self):
953+
def xid(self) -> int:
954954
"""Xen ID.
955955
956956
Or not Xen, but ID.
@@ -970,7 +970,7 @@ def xid(self):
970970
raise
971971

972972
@qubes.stateless_property
973-
def stubdom_uuid(self):
973+
def stubdom_uuid(self) -> str:
974974
stubdom_xid = self.stubdom_xid
975975
if stubdom_xid == -1:
976976
return ""
@@ -981,7 +981,7 @@ def stubdom_uuid(self):
981981
return stubdom_uuid[4:].decode("ascii", "strict")
982982

983983
@qubes.stateless_property
984-
def stubdom_xid(self):
984+
def stubdom_xid(self) -> int:
985985
if not self.is_running():
986986
return -1
987987

@@ -2653,7 +2653,7 @@ def start_time(self):
26532653
return None
26542654

26552655
@qubes.stateless_property
2656-
def icon(self):
2656+
def icon(self) -> str:
26572657
"""freedesktop icon name, suitable for use in
26582658
:py:meth:`PyQt4.QtGui.QIcon.fromTheme`"""
26592659
raw_icon_name = self.label.name

0 commit comments

Comments
 (0)