1
1
import contextlib
2
2
import os
3
- from typing import Dict , Iterator , List , Literal , NamedTuple , Tuple , Union , overload
3
+ from typing import Dict , Generic , Iterator , List , Literal , NamedTuple , Tuple , TypeVar , Union , overload
4
4
5
5
from . import _input , ecodes , util
6
6
9
9
except ImportError :
10
10
from .eventio import EvdevError , EventIO
11
11
12
+ _AnyStr = TypeVar ("_AnyStr" , str , bytes )
13
+
12
14
13
15
class AbsInfo (NamedTuple ):
14
16
"""Absolute axis information.
@@ -100,14 +102,14 @@ def __str__(self) -> str:
100
102
return msg .format (* self ) # pylint: disable=not-an-iterable
101
103
102
104
103
- class InputDevice (EventIO ):
105
+ class InputDevice (EventIO , Generic [ _AnyStr ] ):
104
106
"""
105
107
A linux input device from which input events can be read.
106
108
"""
107
109
108
110
__slots__ = ("path" , "fd" , "info" , "name" , "phys" , "uniq" , "_rawcapabilities" , "version" , "ff_effects_count" )
109
111
110
- def __init__ (self , dev : Union [str , bytes , os .PathLike ]):
112
+ def __init__ (self , dev : Union [_AnyStr , " os.PathLike[_AnyStr]" ]):
111
113
"""
112
114
Arguments
113
115
---------
@@ -116,7 +118,7 @@ def __init__(self, dev: Union[str, bytes, os.PathLike]):
116
118
"""
117
119
118
120
#: Path to input device.
119
- self .path = dev if not hasattr (dev , "__fspath__" ) else dev .__fspath__ ()
121
+ self .path : _AnyStr = dev if not hasattr (dev , "__fspath__" ) else dev .__fspath__ ()
120
122
121
123
# Certain operations are possible only when the device is opened in read-write mode.
122
124
try :
0 commit comments