11import contextlib
22import os
3- from typing import NamedTuple , Tuple , Union
3+ from typing import Dict , Iterator , List , Literal , NamedTuple , Tuple , Union , overload
44
55from . import _input , ecodes , util
66
@@ -95,7 +95,7 @@ class DeviceInfo(NamedTuple):
9595 product : int
9696 version : int
9797
98- def __str__ (self ):
98+ def __str__ (self ) -> str :
9999 msg = "bus: {:04x}, vendor {:04x}, product {:04x}, version {:04x}"
100100 return msg .format (* self ) # pylint: disable=not-an-iterable
101101
@@ -151,7 +151,7 @@ def __init__(self, dev: Union[str, bytes, os.PathLike]):
151151 #: The number of force feedback effects the device can keep in its memory.
152152 self .ff_effects_count = _input .ioctl_EVIOCGEFFECTS (self .fd )
153153
154- def __del__ (self ):
154+ def __del__ (self ) -> None :
155155 if hasattr (self , "fd" ) and self .fd is not None :
156156 try :
157157 self .close ()
@@ -176,7 +176,13 @@ def _capabilities(self, absinfo: bool = True):
176176
177177 return res
178178
179- def capabilities (self , verbose : bool = False , absinfo : bool = True ):
179+ @overload
180+ def capabilities (self , verbose : Literal [False ] = ..., absinfo : bool = ...) -> Dict [int , List [int ]]:
181+ ...
182+ @overload
183+ def capabilities (self , verbose : Literal [True ], absinfo : bool = ...) -> Dict [Tuple [str , int ], List [Tuple [str , int ]]]:
184+ ...
185+ def capabilities (self , verbose : bool = False , absinfo : bool = True ) -> Union [Dict [int , List [int ]], Dict [Tuple [str , int ], List [Tuple [str , int ]]]]:
180186 """
181187 Return the event types that this device supports as a mapping of
182188 supported event types to lists of handled event codes.
@@ -263,7 +269,7 @@ def leds(self, verbose: bool = False):
263269
264270 return leds
265271
266- def set_led (self , led_num : int , value : int ):
272+ def set_led (self , led_num : int , value : int ) -> None :
267273 """
268274 Set the state of the selected LED.
269275
@@ -279,26 +285,26 @@ def __eq__(self, other):
279285 """
280286 return isinstance (other , self .__class__ ) and self .info == other .info and self .path == other .path
281287
282- def __str__ (self ):
288+ def __str__ (self ) -> str :
283289 msg = 'device {}, name "{}", phys "{}", uniq "{}"'
284290 return msg .format (self .path , self .name , self .phys , self .uniq or "" )
285291
286- def __repr__ (self ):
292+ def __repr__ (self ) -> str :
287293 msg = (self .__class__ .__name__ , self .path )
288294 return "{}({!r})" .format (* msg )
289295
290296 def __fspath__ (self ):
291297 return self .path
292298
293- def close (self ):
299+ def close (self ) -> None :
294300 if self .fd > - 1 :
295301 try :
296302 super ().close ()
297303 os .close (self .fd )
298304 finally :
299305 self .fd = - 1
300306
301- def grab (self ):
307+ def grab (self ) -> None :
302308 """
303309 Grab input device using ``EVIOCGRAB`` - other applications will
304310 be unable to receive events until the device is released. Only
@@ -311,7 +317,7 @@ def grab(self):
311317
312318 _input .ioctl_EVIOCGRAB (self .fd , 1 )
313319
314- def ungrab (self ):
320+ def ungrab (self ) -> None :
315321 """
316322 Release device if it has been already grabbed (uses `EVIOCGRAB`).
317323
@@ -324,7 +330,7 @@ def ungrab(self):
324330 _input .ioctl_EVIOCGRAB (self .fd , 0 )
325331
326332 @contextlib .contextmanager
327- def grab_context (self ):
333+ def grab_context (self ) -> Iterator [ None ] :
328334 """
329335 A context manager for the duration of which only the current
330336 process will be able to receive events from the device.
@@ -342,7 +348,7 @@ def upload_effect(self, effect: "ff.Effect"):
342348 ff_id = _input .upload_effect (self .fd , data )
343349 return ff_id
344350
345- def erase_effect (self , ff_id ):
351+ def erase_effect (self , ff_id ) -> None :
346352 """
347353 Erase a force effect from a force feedback device. This also
348354 stops the effect.
@@ -402,7 +408,7 @@ def absinfo(self, axis_num: int):
402408 """
403409 return AbsInfo (* _input .ioctl_EVIOCGABS (self .fd , axis_num ))
404410
405- def set_absinfo (self , axis_num : int , value = None , min = None , max = None , fuzz = None , flat = None , resolution = None ):
411+ def set_absinfo (self , axis_num : int , value = None , min = None , max = None , fuzz = None , flat = None , resolution = None ) -> None :
406412 """
407413 Update :class:`AbsInfo` values. Only specified values will be overwritten.
408414
0 commit comments