Skip to content

Commit 2c623eb

Browse files
committed
More type hints
1 parent bc91d17 commit 2c623eb

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/evdev/ecodes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# When installed, this module is replaced by an ecodes.py generated at
1+
# When installed, this module is replaced by an ecodes.py generated at
22
# build time by genecodes_py.py (see build_ext in setup.py).
33

4-
# This stub exists to make development of evdev itself more convenient.
5-
from . ecodes_runtime import *
4+
# This stub exists to make development of evdev itself more convenient.
5+
from .ecodes_runtime import *

src/evdev/events.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# http://www.kernel.org/doc/Documentation/input/event-codes.txt
3939

4040
# pylint: disable=no-name-in-module
41+
from typing import Final
4142
from .ecodes import ABS, EV_ABS, EV_KEY, EV_REL, EV_SYN, KEY, REL, SYN, keys
4243

4344

@@ -48,21 +49,21 @@ class InputEvent:
4849

4950
def __init__(self, sec, usec, type, code, value):
5051
#: Time in seconds since epoch at which event occurred.
51-
self.sec = sec
52+
self.sec: int = sec
5253

5354
#: Microsecond portion of the timestamp.
54-
self.usec = usec
55+
self.usec: int = usec
5556

5657
#: Event type - one of ``ecodes.EV_*``.
57-
self.type = type
58+
self.type: int = type
5859

5960
#: Event code related to the event type.
60-
self.code = code
61+
self.code: int = code
6162

6263
#: Event value related to the event type.
63-
self.value = value
64+
self.value: int = value
6465

65-
def timestamp(self):
66+
def timestamp(self) -> float:
6667
"""Return event timestamp as a float."""
6768
return self.sec + (self.usec / 1000000.0)
6869

@@ -78,20 +79,20 @@ def __repr__(self):
7879
class KeyEvent:
7980
"""An event generated by a keyboard, button or other key-like devices."""
8081

81-
key_up = 0x0
82-
key_down = 0x1
83-
key_hold = 0x2
82+
key_up: Final[int] = 0x0
83+
key_down: Final[int] = 0x1
84+
key_hold: Final[int] = 0x2
8485

8586
__slots__ = "scancode", "keycode", "keystate", "event"
8687

87-
def __init__(self, event, allow_unknown=False):
88+
def __init__(self, event: InputEvent, allow_unknown: bool = False):
8889
"""
8990
The ``allow_unknown`` argument determines what to do in the event of an event code
9091
for which a key code cannot be found. If ``False`` a ``KeyError`` will be raised.
9192
If ``True`` the keycode will be set to the hex value of the event code.
9293
"""
9394

94-
self.scancode = event.code
95+
self.scancode: int = event.code
9596

9697
if event.value == 0:
9798
self.keystate = KeyEvent.key_up
@@ -109,7 +110,7 @@ def __init__(self, event, allow_unknown=False):
109110
raise
110111

111112
#: Reference to an :class:`InputEvent` instance.
112-
self.event = event
113+
self.event: InputEvent = event
113114

114115
def __str__(self):
115116
try:
@@ -129,9 +130,9 @@ class RelEvent:
129130

130131
__slots__ = "event"
131132

132-
def __init__(self, event):
133+
def __init__(self, event: InputEvent):
133134
#: Reference to an :class:`InputEvent` instance.
134-
self.event = event
135+
self.event: InputEvent = event
135136

136137
def __str__(self):
137138
msg = "relative axis event at {:f}, {}"
@@ -146,9 +147,9 @@ class AbsEvent:
146147

147148
__slots__ = "event"
148149

149-
def __init__(self, event):
150+
def __init__(self, event: InputEvent):
150151
#: Reference to an :class:`InputEvent` instance.
151-
self.event = event
152+
self.event: InputEvent = event
152153

153154
def __str__(self):
154155
msg = "absolute axis event at {:f}, {}"
@@ -166,9 +167,9 @@ class SynEvent:
166167

167168
__slots__ = "event"
168169

169-
def __init__(self, event):
170+
def __init__(self, event: InputEvent):
170171
#: Reference to an :class:`InputEvent` instance.
171-
self.event = event
172+
self.event: InputEvent = event
172173

173174
def __str__(self):
174175
msg = "synchronization event at {:f}, {}"

src/evdev/evtest.py

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
evtest /dev/input/event0 /dev/input/event1
1717
"""
1818

19-
2019
import atexit
2120
import optparse
2221
import re

src/evdev/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .events import event_factory
1010

1111

12-
def list_devices(input_device_dir="/dev/input") -> List[str]:
12+
def list_devices(input_device_dir: Union[str, bytes, os.PathLike] = "/dev/input") -> List[str]:
1313
"""List readable character devices in ``input_device_dir``."""
1414

1515
fns = glob.glob("{}/event*".format(input_device_dir))

0 commit comments

Comments
 (0)