Skip to content

Commit 25cdaae

Browse files
committed
evdevremapkeys: fix type errors reported by pylance
None of these are functional problems, but it's good to keep a clean bill of health.
1 parent f85061b commit 25cdaae

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

evdevremapkeys/evdevremapkeys.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
import functools
2929
from pathlib import Path
3030
import signal
31+
from typing import Optional, Sequence, cast
3132

3233

3334
import evdev
34-
from evdev import ecodes, InputDevice, UInput
35+
from evdev import KeyEvent, ecodes, InputDevice, UInput
3536
import pyudev
3637
from xdg import BaseDirectory
3738
import yaml
@@ -304,7 +305,7 @@ def register_device(device, loop: AbstractEventLoop):
304305
return None
305306
input.grab()
306307

307-
caps = input.capabilities()
308+
caps = cast(dict[int, Sequence[int]], input.capabilities())
308309
# EV_SYN is automatically added to uinput devices
309310
del caps[ecodes.EV_SYN]
310311

@@ -409,14 +410,15 @@ def list_devices():
409410

410411

411412
def read_events(req_device):
413+
found: Optional[InputDevice] = None
412414
for device in list_devices():
413415
# Look in all 3 identifiers + event number
414416
if req_device in device or req_device == device[0].replace(
415417
"/dev/input/event", ""
416418
):
417-
found = evdev.InputDevice(device[0])
419+
found = InputDevice(device[0])
418420

419-
if "found" not in locals():
421+
if not found:
420422
print(
421423
"Device not found. \n"
422424
"Please use --list-devices to view a list of available devices."
@@ -430,6 +432,7 @@ def read_events(req_device):
430432
try:
431433
if event.type == evdev.ecodes.EV_KEY:
432434
categorized = evdev.categorize(event)
435+
assert isinstance(categorized, KeyEvent)
433436
if categorized.keystate == 1:
434437
keycode = (
435438
categorized.keycode

0 commit comments

Comments
 (0)