Skip to content

Commit 890a570

Browse files
committed
add back type annotations to layout base
1 parent 8b3385d commit 890a570

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

adafruit_hid/keyboard_layout_base.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
"""
1111

1212

13+
try:
14+
from typing import Tuple
15+
from .keyboard import Keyboard
16+
except ImportError:
17+
pass
18+
19+
1320
__version__ = "0.0.0-auto.0"
1421
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HID.git"
1522

@@ -32,7 +39,7 @@ class KeyboardLayoutBase:
3239
HIGHER_ASCII = {}
3340
COMBINED_KEYS = {}
3441

35-
def __init__(self, keyboard):
42+
def __init__(self, keyboard: Keyboard) -> None:
3643
"""Specify the layout for the given keyboard.
3744
3845
:param keyboard: a Keyboard object. Write characters to this keyboard when requested.
@@ -44,7 +51,7 @@ def __init__(self, keyboard):
4451
"""
4552
self.keyboard = keyboard
4653

47-
def _write(self, keycode, altgr=False):
54+
def _write(self, keycode: int, altgr: bool = False) -> None:
4855
"""Type a key combination based on shift bit and altgr bool
4956
5057
:param keycode: int value of the keycode, with the shift bit.
@@ -60,7 +67,7 @@ def _write(self, keycode, altgr=False):
6067
self.keyboard.press(keycode)
6168
self.keyboard.release_all()
6269

63-
def write(self, string):
70+
def write(self, string: str) -> None:
6471
"""Type the string by pressing and releasing keys on my keyboard.
6572
6673
:param string: A string of ASCII characters.
@@ -94,7 +101,7 @@ def write(self, string):
94101
)
95102
)
96103

97-
def keycodes(self, char):
104+
def keycodes(self, char: str) -> Tuple[int, ...]:
98105
"""Return a tuple of keycodes needed to type the given character.
99106
100107
:param char: A single UTF8 character in a string.
@@ -131,7 +138,7 @@ def keycodes(self, char):
131138

132139
return codes
133140

134-
def _above128char_to_keycode(self, char):
141+
def _above128char_to_keycode(self, char: str) -> int:
135142
"""Return keycode for above 128 ascii codes.
136143
137144
A character can be indexed by the char itself or its int ord() value.
@@ -145,7 +152,7 @@ def _above128char_to_keycode(self, char):
145152
return self.HIGHER_ASCII[char]
146153
return 0
147154

148-
def _char_to_keycode(self, char):
155+
def _char_to_keycode(self, char: str) -> int:
149156
"""Return the HID keycode for the given ASCII character, with the SHIFT_FLAG possibly set.
150157
151158
If the character requires pressing the Shift key, the SHIFT_FLAG bit is set.

0 commit comments

Comments
 (0)