1
1
import contextlib
2
2
import os
3
- from typing import NamedTuple , Tuple , Union
3
+ from typing import Dict , Iterator , List , Literal , NamedTuple , Tuple , Union , overload
4
4
5
5
from . import _input , ecodes , util
6
6
@@ -95,7 +95,7 @@ class DeviceInfo(NamedTuple):
95
95
product : int
96
96
version : int
97
97
98
- def __str__ (self ):
98
+ def __str__ (self ) -> str :
99
99
msg = "bus: {:04x}, vendor {:04x}, product {:04x}, version {:04x}"
100
100
return msg .format (* self ) # pylint: disable=not-an-iterable
101
101
@@ -151,7 +151,7 @@ def __init__(self, dev: Union[str, bytes, os.PathLike]):
151
151
#: The number of force feedback effects the device can keep in its memory.
152
152
self .ff_effects_count = _input .ioctl_EVIOCGEFFECTS (self .fd )
153
153
154
- def __del__ (self ):
154
+ def __del__ (self ) -> None :
155
155
if hasattr (self , "fd" ) and self .fd is not None :
156
156
try :
157
157
self .close ()
@@ -176,7 +176,13 @@ def _capabilities(self, absinfo: bool = True):
176
176
177
177
return res
178
178
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 ]]]]:
180
186
"""
181
187
Return the event types that this device supports as a mapping of
182
188
supported event types to lists of handled event codes.
@@ -263,7 +269,7 @@ def leds(self, verbose: bool = False):
263
269
264
270
return leds
265
271
266
- def set_led (self , led_num : int , value : int ):
272
+ def set_led (self , led_num : int , value : int ) -> None :
267
273
"""
268
274
Set the state of the selected LED.
269
275
@@ -279,26 +285,26 @@ def __eq__(self, other):
279
285
"""
280
286
return isinstance (other , self .__class__ ) and self .info == other .info and self .path == other .path
281
287
282
- def __str__ (self ):
288
+ def __str__ (self ) -> str :
283
289
msg = 'device {}, name "{}", phys "{}", uniq "{}"'
284
290
return msg .format (self .path , self .name , self .phys , self .uniq or "" )
285
291
286
- def __repr__ (self ):
292
+ def __repr__ (self ) -> str :
287
293
msg = (self .__class__ .__name__ , self .path )
288
294
return "{}({!r})" .format (* msg )
289
295
290
296
def __fspath__ (self ):
291
297
return self .path
292
298
293
- def close (self ):
299
+ def close (self ) -> None :
294
300
if self .fd > - 1 :
295
301
try :
296
302
super ().close ()
297
303
os .close (self .fd )
298
304
finally :
299
305
self .fd = - 1
300
306
301
- def grab (self ):
307
+ def grab (self ) -> None :
302
308
"""
303
309
Grab input device using ``EVIOCGRAB`` - other applications will
304
310
be unable to receive events until the device is released. Only
@@ -311,7 +317,7 @@ def grab(self):
311
317
312
318
_input .ioctl_EVIOCGRAB (self .fd , 1 )
313
319
314
- def ungrab (self ):
320
+ def ungrab (self ) -> None :
315
321
"""
316
322
Release device if it has been already grabbed (uses `EVIOCGRAB`).
317
323
@@ -324,7 +330,7 @@ def ungrab(self):
324
330
_input .ioctl_EVIOCGRAB (self .fd , 0 )
325
331
326
332
@contextlib .contextmanager
327
- def grab_context (self ):
333
+ def grab_context (self ) -> Iterator [ None ] :
328
334
"""
329
335
A context manager for the duration of which only the current
330
336
process will be able to receive events from the device.
@@ -342,7 +348,7 @@ def upload_effect(self, effect: "ff.Effect"):
342
348
ff_id = _input .upload_effect (self .fd , data )
343
349
return ff_id
344
350
345
- def erase_effect (self , ff_id ):
351
+ def erase_effect (self , ff_id ) -> None :
346
352
"""
347
353
Erase a force effect from a force feedback device. This also
348
354
stops the effect.
@@ -402,7 +408,7 @@ def absinfo(self, axis_num: int):
402
408
"""
403
409
return AbsInfo (* _input .ioctl_EVIOCGABS (self .fd , axis_num ))
404
410
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 :
406
412
"""
407
413
Update :class:`AbsInfo` values. Only specified values will be overwritten.
408
414
0 commit comments