11import contextlib
22import 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
44
55from . import _input , ecodes , util
66
99except ImportError :
1010 from .eventio import EvdevError , EventIO
1111
12+ _AnyStr = TypeVar ("_AnyStr" , str , bytes )
13+
1214
1315class AbsInfo (NamedTuple ):
1416 """Absolute axis information.
@@ -100,14 +102,14 @@ def __str__(self) -> str:
100102 return msg .format (* self ) # pylint: disable=not-an-iterable
101103
102104
103- class InputDevice (EventIO ):
105+ class InputDevice (EventIO , Generic [ _AnyStr ] ):
104106 """
105107 A linux input device from which input events can be read.
106108 """
107109
108110 __slots__ = ("path" , "fd" , "info" , "name" , "phys" , "uniq" , "_rawcapabilities" , "version" , "ff_effects_count" )
109111
110- def __init__ (self , dev : Union [str , bytes , os .PathLike ]):
112+ def __init__ (self , dev : Union [_AnyStr , os .PathLike [ _AnyStr ] ]):
111113 """
112114 Arguments
113115 ---------
@@ -116,7 +118,7 @@ def __init__(self, dev: Union[str, bytes, os.PathLike]):
116118 """
117119
118120 #: 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__ ()
120122
121123 # Certain operations are possible only when the device is opened in read-write mode.
122124 try :
0 commit comments