Skip to content

Commit 57b55bb

Browse files
committed
add type annotations to layout base
1 parent 74c992e commit 57b55bb

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

@@ -50,7 +57,7 @@ class KeyboardLayoutBase:
5057
``KKK KKKK`` is the (low) ASCII code for the second character.
5158
"""
5259

53-
def __init__(self, keyboard):
60+
def __init__(self, keyboard: Keyboard) -> None:
5461
"""Specify the layout for the given keyboard.
5562
5663
:param keyboard: a Keyboard object. Write characters to this keyboard when requested.
@@ -62,7 +69,7 @@ def __init__(self, keyboard):
6269
"""
6370
self.keyboard = keyboard
6471

65-
def _write(self, keycode, altgr=False):
72+
def _write(self, keycode: int, altgr: bool = False) -> None:
6673
"""Type a key combination based on shift bit and altgr bool
6774
6875
:param keycode: int value of the keycode, with the shift bit.
@@ -78,7 +85,7 @@ def _write(self, keycode, altgr=False):
7885
self.keyboard.press(keycode)
7986
self.keyboard.release_all()
8087

81-
def write(self, string):
88+
def write(self, string: str) -> None:
8289
"""Type the string by pressing and releasing keys on my keyboard.
8390
8491
:param string: A string of UTF-8 characters to convert to key presses and send.
@@ -112,7 +119,7 @@ def write(self, string):
112119
)
113120
)
114121

115-
def keycodes(self, char):
122+
def keycodes(self, char: str) -> Tuple[int, ...]:
116123
"""Return a tuple of keycodes needed to type the given character.
117124
118125
:param char: A single UTF8 character in a string.
@@ -149,7 +156,7 @@ def keycodes(self, char):
149156

150157
return codes
151158

152-
def _above128char_to_keycode(self, char):
159+
def _above128char_to_keycode(self, char: str) -> int:
153160
"""Return keycode for above 128 utf8 codes.
154161
155162
A character can be indexed by the char itself or its int ord() value.
@@ -163,7 +170,7 @@ def _above128char_to_keycode(self, char):
163170
return self.HIGHER_ASCII[char]
164171
return 0
165172

166-
def _char_to_keycode(self, char):
173+
def _char_to_keycode(self, char: str) -> int:
167174
"""Return the HID keycode for the given character, with the SHIFT_FLAG possibly set.
168175
169176
If the character requires pressing the Shift key, the SHIFT_FLAG bit is set.

0 commit comments

Comments
 (0)