Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ jobs:
task: make -f Makefile fmt-travis
- dependencies: yamllint
task: make -f Makefile yamllint
- dependencies: pylint python3-into-dbus-python python3-setuptools
task: PYTHONPATH=./src make -f Makefile lint
- dependencies: >
libatomic
pylint
python3-into-dbus-python
python3-setuptools
task: >
PATH=${PATH}:/github/home/.local/bin
PYTHONPATH=./src make -f Makefile lint
- dependencies: python3-into-dbus-python python3-setuptools
task: PYTHONPATH=./src make -f Makefile test
- dependencies: >
Expand All @@ -39,7 +45,10 @@ jobs:
run: >
dnf install -y
make
pip
${{ matrix.dependencies }}
- name: Install pyright
run: pip install --user pyright
- name: ${{ matrix.task }}
run: ${{ matrix.task }}

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lint:
pylint setup.py
pylint src/dbus_python_client_gen
pylint tests --ignore=_introspect.py
pyright

.PHONY: test
test:
Expand Down
48 changes: 31 additions & 17 deletions src/dbus_python_client_gen/_invokers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"""
# isort: STDLIB
import types
import xml.etree.ElementTree as ET # nosec B405
from typing import Any, Callable, Mapping, MutableMapping, Sequence, Type

# isort: THIRDPARTY
import dbus
from dbus.proxies import ProxyObject

# isort: FIRSTPARTY
from into_dbus_python import IntoDPError, xformer, xformers
Expand All @@ -24,7 +27,9 @@
)


def prop_builder(interface_name, properties, timeout):
def prop_builder(
interface_name: str, properties: Sequence[ET.Element], timeout: int
) -> Callable[[MutableMapping[str, Type]], None]:
"""
Returns a function that builds a property interface based on arguments.

Expand All @@ -51,14 +56,14 @@ def prop_builder(interface_name, properties, timeout):
:raises DPClientGenerationError:
"""

def build_property_getter(name):
def build_property_getter(name: str) -> Callable[[ProxyObject], Any]:
"""
Build a single property getter for this class.

:param str name: the name of the property
"""

def dbus_func(proxy_object):
def dbus_func(proxy_object: ProxyObject) -> Any:
"""
The property getter.

Expand All @@ -82,7 +87,9 @@ def dbus_func(proxy_object):

return dbus_func

def build_property_setter(name, signature):
def build_property_setter(
name: str, signature
) -> Callable[[ProxyObject, Any], None]:
"""
Build a single property setter for this class.

Expand All @@ -101,7 +108,7 @@ def build_property_setter(name, signature):
fmt_str % (signature, name, interface_name)
) from err

def dbus_func(proxy_object, value):
def dbus_func(proxy_object: ProxyObject, value: Any) -> None:
"""
The property setter.

Expand All @@ -120,7 +127,7 @@ def dbus_func(proxy_object, value):
) from err

try: # pragma: no cover
return proxy_object.Set(
proxy_object.Set(
interface_name,
name,
arg,
Expand All @@ -138,7 +145,9 @@ def dbus_func(proxy_object, value):

return dbus_func

def build_property(access, name, signature):
def build_property(
access: str, name: str, signature: str
) -> Callable[[MutableMapping[str, Callable]], None]:
"""
Select among getter, setter, or both methods for a given property.

Expand All @@ -151,7 +160,7 @@ def build_property(access, name, signature):
if access == "read":
getter = build_property_getter(name)

def prop_method_builder(namespace):
def prop_method_builder(namespace: MutableMapping[str, Callable]) -> None:
"""
Attaches getter to namespace.
"""
Expand All @@ -160,7 +169,7 @@ def prop_method_builder(namespace):
elif access == "write": # pragma: no cover
setter = build_property_setter(name, signature)

def prop_method_builder(namespace):
def prop_method_builder(namespace: MutableMapping[str, Callable]) -> None:
"""
Attaches setter to namespace
"""
Expand All @@ -170,7 +179,7 @@ def prop_method_builder(namespace):
getter = build_property_getter(name)
setter = build_property_setter(name, signature)

def prop_method_builder(namespace):
def prop_method_builder(namespace: MutableMapping[str, Callable]) -> None:
"""
Attaches getter and setter to namespace
"""
Expand All @@ -179,7 +188,7 @@ def prop_method_builder(namespace):

return prop_method_builder

def builder(namespace):
def builder(namespace: MutableMapping[str, Type]) -> None:
"""
Fills the namespace of the parent class with class members that are
classes. Each class member has the name of a property, and each
Expand Down Expand Up @@ -233,7 +242,9 @@ class has up to two static methods, a Get method if the property is
return builder


def method_builder(interface_name, methods, timeout):
def method_builder(
interface_name: str, methods: Sequence[ET.Element], timeout: int
) -> Callable[[MutableMapping[str, Callable]], None]:
"""
Returns a function that builds a method interface based on 'spec'.

Expand All @@ -256,7 +267,10 @@ def method_builder(interface_name, methods, timeout):
:raises DPClientGenerationError:
"""

def build_method(name, inargs):
def build_method(
name: str,
inargs: Sequence[ET.Element],
) -> Callable[[ProxyObject, Mapping[str, Any]], Any]:
"""
Build a method for this class.

Expand Down Expand Up @@ -295,7 +309,7 @@ def build_method(name, inargs):
) from err
arg_names_set = frozenset(arg_names)

def dbus_func(proxy_object, func_args):
def dbus_func(proxy_object: ProxyObject, func_args: Mapping[str, Any]) -> Any:
"""
The method proper.

Expand Down Expand Up @@ -356,7 +370,7 @@ def dbus_func(proxy_object, func_args):

return dbus_func

def builder(namespace):
def builder(namespace: MutableMapping[str, Callable]) -> None:
"""
Fills the namespace of the parent class with class members that are
methods. Each method takes a proxy object and a set of keyword
Expand Down Expand Up @@ -395,7 +409,7 @@ def builder(namespace):
return builder


def make_class(name, spec, timeout=-1):
def make_class(name: str, spec: ET.Element, timeout: int = -1) -> Type:
"""
Make a class, name, from the given spec.
The class defines static properties and methods according to the spec.
Expand All @@ -418,7 +432,7 @@ def make_class(name, spec, timeout=-1):
)
prop_builder_arg = prop_builder(interface_name, spec.findall("./property"), timeout)

def builder(namespace):
def builder(namespace: MutableMapping[str, Type]) -> None:
"""
Fills the namespace of the parent class with two class members,
Properties and Methods. Both of these are classes which themselves
Expand Down