Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Make Mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
kalkin committed Jun 27, 2017
1 parent 4c3fc37 commit 6626dd7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
8 changes: 4 additions & 4 deletions qubesdbus/domain_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, qubes_data: DBusProperties, domains: List[DBusProperties]) ->
'Unknown': lambda _, __: None,
}
self.signal_matches = {
} # type: Dict[dbus.ObjectPath, List[DBusSignalMatch]]
} # type: Dict[str, List[DBusSignalMatch]]

for domain in self.managed_objects:
obj_path = domain._object_path # pylint: disable=protected-access
Expand All @@ -94,7 +94,7 @@ def GetManagedObjects(self):
for o in self.managed_objects
}

def _setup_signals(self, obj_path: dbus.ObjectPath):
def _setup_signals(self, obj_path: str):
def emit_state_signal(dbus_interface,
changed_properties: DBusProperties,
invalidated: dbus.Array=None # pylint: disable=unused-argument
Expand Down Expand Up @@ -166,7 +166,7 @@ def AddDomain(self, vm, execute = False):
self.managed_objects.append(domain)
log.info('Added domain %s', vm['name'])
# pylint: disable=protected-access
obj_path = domain._object_path # type: dbus.Object_Path
obj_path = domain._object_path
self._setup_signals(obj_path)
self.DomainAdded(INTERFACE, obj_path)
return True
Expand Down Expand Up @@ -195,7 +195,7 @@ def RemoveDomain(self, vm_dbus_path, execute=False):
return False
for vm in self.managed_objects:
# pylint: disable=protected-access
obj_path = vm._object_path # type: dbus.ObjectPath
obj_path = vm._object_path
if obj_path == vm_dbus_path:
for signal_matcher in self.signal_matches[obj_path]:
self.bus.remove_signal_receiver(signal_matcher)
Expand Down
1 change: 0 additions & 1 deletion qubesdbus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,3 @@ def __init__(self, bus_name, prefix_path, data):
name = data['name']
obj_path = os.path.join(prefix_path, 'labels', name)
super(Label, self).__init__(bus_name, obj_path, Label.INTERFACE, data)

31 changes: 11 additions & 20 deletions qubesdbus/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
''' Service classes '''

from __future__ import absolute_import
from typing import Any

import logging

Expand All @@ -30,42 +31,32 @@

from systemd.journal import JournalHandler

from .constants import NAME_PREFIX, PATH_PREFIX, VERSION

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

try:
# Check mypy types. pylint: disable=ungrouped-imports, unused-import
from typing import Any
from dbus._dbus import SessionBus
from dbus.service import BusName
except ImportError:
pass
from dbus.service import BusName


class DbusServiceObject(dbus.service.Object):
''' A class implementing a useful shortcut for writing own D-Bus Services
'''

def __init__(self, bus_name: dbus.service.BusName, obj_path: str):
super(DbusServiceObject, self).__init__(bus_name=bus_name,
object_path=obj_path)
def __init__(self, bus_name: BusName, obj_path: str) -> None:
super().__init__(bus_name=bus_name, object_path=obj_path)


class ObjectManager(DbusServiceObject):
''' Provides a class implementing the `org.freedesktop.DBus.ObjectManager`
interface.
'''

# pylint: disable=too-few-public-methods
def __init__(self, name: str, obj_path: str):
def __init__(self, name: str, obj_path: str) -> None:
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(name, bus=bus, allow_replacement=True,
replace_existing=True)
bus_name = BusName(name, bus=bus, allow_replacement=True,
replace_existing=True)
super().__init__(bus_name=bus_name, obj_path=obj_path)
self.bus_name = bus_name
self.bus = bus
self.managed_objects = [] # type: PropertiesObject
self.managed_objects = [] # type: List[PropertiesObject]

@dbus.service.method(dbus_interface="org.freedesktop.DBus.ObjectManager",
out_signature="a{oa{sa{sv}}}")
Expand All @@ -81,8 +72,8 @@ class PropertiesObject(DbusServiceObject):
# pylint: disable=invalid-name
''' Implements `org.freedesktop.DBus.Properties` interface. '''

def __init__(self, bus_name: dbus.service.BusName, obj_path: str,
iface: str, data: dict):
def __init__(self, bus_name: BusName, obj_path: str, iface: str,
data: dict) -> None:
assert iface, "No interface provided for PropertiesObject"

super().__init__(bus_name, obj_path)
Expand All @@ -107,7 +98,7 @@ def GetAll(self, _):
return self.properties

@dbus.service.method(dbus_interface="org.freedesktop.DBus.Properties")
def Set(self, interface, name, value): # type: (str, dbus.String, Any) -> None
def Set(self, interface: str, name: str, value: Any) -> None:
''' Set a property value.
''' # pylint: disable=unused-argument
new_value = value
Expand Down

0 comments on commit 6626dd7

Please sign in to comment.