66"""
77# isort: STDLIB
88import types
9+ import xml .etree .ElementTree as ET # nosec B405
10+ from typing import Any , Callable , Mapping , MutableMapping , Sequence , Type
911
1012# isort: THIRDPARTY
1113import dbus
14+ from dbus .proxies import ProxyObject
1215
1316# isort: FIRSTPARTY
1417from into_dbus_python import IntoDPError , xformer , xformers
2427)
2528
2629
27- def prop_builder (interface_name , properties , timeout ):
30+ def prop_builder (
31+ interface_name : str , properties : Sequence [ET .Element ], timeout : int
32+ ) -> Callable [[MutableMapping [str , Type ]], None ]:
2833 """
2934 Returns a function that builds a property interface based on arguments.
3035
@@ -51,14 +56,14 @@ def prop_builder(interface_name, properties, timeout):
5156 :raises DPClientGenerationError:
5257 """
5358
54- def build_property_getter (name ) :
59+ def build_property_getter (name : str ) -> Callable [[ ProxyObject ], Any ] :
5560 """
5661 Build a single property getter for this class.
5762
5863 :param str name: the name of the property
5964 """
6065
61- def dbus_func (proxy_object ) :
66+ def dbus_func (proxy_object : ProxyObject ) -> Any :
6267 """
6368 The property getter.
6469
@@ -82,7 +87,9 @@ def dbus_func(proxy_object):
8287
8388 return dbus_func
8489
85- def build_property_setter (name , signature ):
90+ def build_property_setter (
91+ name : str , signature
92+ ) -> Callable [[ProxyObject , Any ], None ]:
8693 """
8794 Build a single property setter for this class.
8895
@@ -101,7 +108,7 @@ def build_property_setter(name, signature):
101108 fmt_str % (signature , name , interface_name )
102109 ) from err
103110
104- def dbus_func (proxy_object , value ) :
111+ def dbus_func (proxy_object : ProxyObject , value : Any ) -> None :
105112 """
106113 The property setter.
107114
@@ -120,7 +127,7 @@ def dbus_func(proxy_object, value):
120127 ) from err
121128
122129 try : # pragma: no cover
123- return proxy_object .Set (
130+ proxy_object .Set (
124131 interface_name ,
125132 name ,
126133 arg ,
@@ -138,7 +145,7 @@ def dbus_func(proxy_object, value):
138145
139146 return dbus_func
140147
141- def build_property (access , name , signature ):
148+ def build_property (access : str , name : str , signature ):
142149 """
143150 Select among getter, setter, or both methods for a given property.
144151
@@ -179,7 +186,7 @@ def prop_method_builder(namespace):
179186
180187 return prop_method_builder
181188
182- def builder (namespace ) :
189+ def builder (namespace : MutableMapping [ str , Type ]) -> None :
183190 """
184191 Fills the namespace of the parent class with class members that are
185192 classes. Each class member has the name of a property, and each
@@ -233,7 +240,7 @@ class has up to two static methods, a Get method if the property is
233240 return builder
234241
235242
236- def method_builder (interface_name , methods , timeout ):
243+ def method_builder (interface_name : str , methods : Sequence , timeout : int ):
237244 """
238245 Returns a function that builds a method interface based on 'spec'.
239246
@@ -256,7 +263,7 @@ def method_builder(interface_name, methods, timeout):
256263 :raises DPClientGenerationError:
257264 """
258265
259- def build_method (name , inargs ):
266+ def build_method (name : str , inargs ) -> Callable :
260267 """
261268 Build a method for this class.
262269
@@ -295,7 +302,7 @@ def build_method(name, inargs):
295302 ) from err
296303 arg_names_set = frozenset (arg_names )
297304
298- def dbus_func (proxy_object , func_args ) :
305+ def dbus_func (proxy_object : ProxyObject , func_args : Mapping [ str , Any ]) -> Any :
299306 """
300307 The method proper.
301308
@@ -356,7 +363,7 @@ def dbus_func(proxy_object, func_args):
356363
357364 return dbus_func
358365
359- def builder (namespace ) :
366+ def builder (namespace : MutableMapping [ str , Callable ]) -> None :
360367 """
361368 Fills the namespace of the parent class with class members that are
362369 methods. Each method takes a proxy object and a set of keyword
@@ -395,7 +402,7 @@ def builder(namespace):
395402 return builder
396403
397404
398- def make_class (name , spec , timeout = - 1 ):
405+ def make_class (name : str , spec : ET . Element , timeout : int = - 1 ) -> Type :
399406 """
400407 Make a class, name, from the given spec.
401408 The class defines static properties and methods according to the spec.
@@ -418,7 +425,7 @@ def make_class(name, spec, timeout=-1):
418425 )
419426 prop_builder_arg = prop_builder (interface_name , spec .findall ("./property" ), timeout )
420427
421- def builder (namespace ) :
428+ def builder (namespace : MutableMapping [ str , Type ]) -> None :
422429 """
423430 Fills the namespace of the parent class with two class members,
424431 Properties and Methods. Both of these are classes which themselves
0 commit comments