Skip to content

Commit 607c162

Browse files
committed
Add typing
1 parent b1aabdd commit 607c162

File tree

8 files changed

+68
-28
lines changed

8 files changed

+68
-28
lines changed

adafruit_boardtest/boardtest_gpio.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
import digitalio
3030
import supervisor
3131

32+
try:
33+
from typing import Any, Sequence, Tuple, List
34+
except ImportError:
35+
pass
36+
3237
__version__ = "0.0.0-auto.0"
3338
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
3439

@@ -43,7 +48,7 @@
4348
NA = "N/A"
4449

4550
# Determine if given value is a number
46-
def _is_number(val):
51+
def _is_number(val: Any) -> bool:
4752
try:
4853
float(val)
4954
return True
@@ -52,13 +57,13 @@ def _is_number(val):
5257

5358

5459
# Release pins
55-
def _deinit_pins(gpios):
60+
def _deinit_pins(gpios: Sequence[digitalio.DigitalInOut]) -> None:
5661
for g in gpios:
5762
g.deinit()
5863

5964

6065
# Toggle IO pins while waiting for answer
61-
def _toggle_wait(gpios):
66+
def _toggle_wait(gpios: Sequence[digitalio.DigitalInOut]) -> bool:
6267

6368
timestamp = time.monotonic()
6469
led_state = False
@@ -79,7 +84,7 @@ def _toggle_wait(gpios):
7984
return bool(answer == "y")
8085

8186

82-
def run_test(pins):
87+
def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:
8388

8489
"""
8590
Toggles all available GPIO on and off repeatedly.

adafruit_boardtest/boardtest_i2c.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
import board
3434
import busio
3535

36+
try:
37+
from typing import Tuple, Sequence, List
38+
except ImportError:
39+
pass
40+
3641
__version__ = "0.0.0-auto.0"
3742
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
3843

@@ -51,7 +56,7 @@
5156
NA = "N/A"
5257

5358
# Open comms to I2C EEPROM by trying a write to memory address
54-
def _eeprom_i2c_wait(i2c, i2c_addr, mem_addr, timeout=1.0):
59+
def _eeprom_i2c_wait(i2c: busio.I2C, i2c_addr: int, mem_addr: int, timeout: float = 1.0) -> bool:
5560

5661
# Try to access the I2C EEPROM (it becomes unresonsive during a write)
5762
timestamp = time.monotonic()
@@ -66,7 +71,7 @@ def _eeprom_i2c_wait(i2c, i2c_addr, mem_addr, timeout=1.0):
6671

6772

6873
# Write to address. Returns status (True for successful write, False otherwise)
69-
def _eeprom_i2c_write_byte(i2c, i2c_addr, mem_addr, mem_data):
74+
def _eeprom_i2c_write_byte(i2c: busio.I2C, i2c_addr: int, mem_addr: int, mem_data: int) -> bool:
7075

7176
# Make sure address is only one byte:
7277
if mem_addr > 255:
@@ -86,7 +91,7 @@ def _eeprom_i2c_write_byte(i2c, i2c_addr, mem_addr, mem_data):
8691

8792

8893
# Read from address. Returns tuple [status, result]
89-
def _eeprom_i2c_read_byte(i2c, i2c_addr, mem_addr, timeout=1.0):
94+
def _eeprom_i2c_read_byte(i2c: busio.I2C, i2c_addr: int, mem_addr: int, timeout: float = 1.0) -> Tuple[bool, bytearray]:
9095

9196
# Make sure address is only one byte:
9297
if mem_addr > 255:
@@ -103,7 +108,7 @@ def _eeprom_i2c_read_byte(i2c, i2c_addr, mem_addr, timeout=1.0):
103108
return True, buf
104109

105110

106-
def run_test(pins, sda_pin=SDA_PIN_NAME, scl_pin=SCL_PIN_NAME):
111+
def run_test(pins: Sequence[str], sda_pin: str = SDA_PIN_NAME, scl_pin: str = SCL_PIN_NAME) -> Tuple[str, List[str]]:
107112

108113
"""
109114
Performs random writes and reads to I2C EEPROM.

adafruit_boardtest/boardtest_led.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
import digitalio
2929
import supervisor
3030

31+
try:
32+
from typing import Sequence, Tuple, List
33+
except ImportError:
34+
pass
35+
3136
__version__ = "0.0.0-auto.0"
3237
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
3338

@@ -42,7 +47,7 @@
4247
NA = "N/A"
4348

4449
# Toggle IO pins while waiting for answer
45-
def _toggle_wait(led_pins):
50+
def _toggle_wait(led_pins: Sequence[str]) -> bool:
4651
timestamp = time.monotonic()
4752
led_state = False
4853
print("Are the pins listed above toggling? [y/n]")
@@ -77,7 +82,7 @@ def _toggle_wait(led_pins):
7782
return False
7883

7984

80-
def run_test(pins):
85+
def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:
8186

8287
"""
8388
Toggles the onboard LED(s) on and off.

adafruit_boardtest/boardtest_sd.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
import adafruit_sdcard
3838
import storage
3939

40+
try:
41+
from typing import Sequence, Tuple, List
42+
except ImportError:
43+
pass
44+
4045
__version__ = "0.0.0-auto.0"
4146
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
4247

@@ -58,13 +63,13 @@
5863

5964

6065
def run_test(
61-
pins,
62-
mosi_pin=MOSI_PIN_NAME,
63-
miso_pin=MISO_PIN_NAME,
64-
sck_pin=SCK_PIN_NAME,
65-
cs_pin=CS_PIN_NAME,
66+
pins: Sequence[str],
67+
mosi_pin: str = MOSI_PIN_NAME,
68+
miso_pin: str = MISO_PIN_NAME,
69+
sck_pin: str = SCK_PIN_NAME,
70+
cs_pin: str = CS_PIN_NAME,
6671
filename: str = FILENAME
67-
):
72+
) -> Tuple[str, List[str]]:
6873

6974
"""
7075
Performs random writes and reads to file on attached SD card.

adafruit_boardtest/boardtest_sd_cd.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
import board
3030
import digitalio
3131

32+
try:
33+
from typing import Sequence, Tuple, List
34+
except ImportError:
35+
pass
36+
3237
__version__ = "0.0.0-auto.0"
3338
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
3439

@@ -41,7 +46,7 @@
4146
NA = "N/A"
4247

4348

44-
def run_test(pins, cd_pin=SD_CD_PIN_NAME):
49+
def run_test(pins: Sequence[str], cd_pin: str = SD_CD_PIN_NAME) -> Tuple[str, List[str]]:
4550

4651
"""
4752
Checks status of CD pin as user inserts and removes SD card.

adafruit_boardtest/boardtest_spi.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
import digitalio
3737
import busio
3838

39+
try:
40+
from typing import Tuple, Sequence, List
41+
except ImportError:
42+
pass
43+
3944
__version__ = "0.0.0-auto.0"
4045
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
4146

@@ -64,7 +69,7 @@
6469
NA = "N/A"
6570

6671
# Wait for WIP bit to go low
67-
def _eeprom_spi_wait(spi, csel, timeout=1.0):
72+
def _eeprom_spi_wait(spi: busio.SPI, csel: digitalio.DigitalInOut, timeout: float = 1.0) -> bool:
6873

6974
# Continually read from STATUS register
7075
timestamp = time.monotonic()
@@ -85,7 +90,7 @@ def _eeprom_spi_wait(spi, csel, timeout=1.0):
8590

8691

8792
# Write to address. Returns status (True for successful write, False otherwise)
88-
def _eeprom_spi_write_byte(spi, csel, address, data, timeout=1.0):
93+
def _eeprom_spi_write_byte(spi: busio.SPI, csel: digitalio.DigitalInOut, address: int, data: int, timeout: float = 1.0) -> bool:
8994

9095
# Make sure address is only one byte:
9196
if address > 255:
@@ -113,7 +118,7 @@ def _eeprom_spi_write_byte(spi, csel, address, data, timeout=1.0):
113118

114119

115120
# Read from address. Returns tuple [status, result]
116-
def _eeprom_spi_read_byte(spi, csel, address, timeout=1.0):
121+
def _eeprom_spi_read_byte(spi: busio.SPI, csel: digitalio.DigitalInOut, address: int, timeout: float = 1.0) -> Tuple[bool, bytearray]:
117122

118123
# Make sure address is only one byte:
119124
if address > 255:
@@ -134,12 +139,12 @@ def _eeprom_spi_read_byte(spi, csel, address, timeout=1.0):
134139

135140

136141
def run_test(
137-
pins,
138-
mosi_pin=MOSI_PIN_NAME,
139-
miso_pin=MISO_PIN_NAME,
140-
sck_pin=SCK_PIN_NAME,
141-
cs_pin=CS_PIN_NAME,
142-
):
142+
pins: Sequence[str],
143+
mosi_pin: str = MOSI_PIN_NAME,
144+
miso_pin: str = MISO_PIN_NAME,
145+
sck_pin: str = SCK_PIN_NAME,
146+
cs_pin: str = CS_PIN_NAME,
147+
) -> Tuple[str, List[str]]:
143148

144149
"""
145150
Performs random writes and reads to file on attached SD card.

adafruit_boardtest/boardtest_uart.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
import board
3030
import busio
3131

32+
try:
33+
from typing import Sequence, Tuple, List
34+
except ImportError:
35+
pass
36+
3237
__version__ = "0.0.0-auto.0"
3338
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
3439

@@ -46,7 +51,7 @@
4651
NA = "N/A"
4752

4853

49-
def run_test(pins, tx_pin=TX_PIN_NAME, rx_pin=RX_PIN_NAME, baud_rate=BAUD_RATE):
54+
def run_test(pins: Sequence[str], tx_pin: str = TX_PIN_NAME, rx_pin: str = RX_PIN_NAME, baud_rate: int = BAUD_RATE) -> Tuple[str, List[str]]:
5055

5156
"""
5257
Performs random writes out of TX pin and reads on RX.

adafruit_boardtest/boardtest_voltage_monitor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
import board
3232
import analogio
3333

34+
try:
35+
from typing import Sequence, Tuple, List
36+
except ImportError:
37+
pass
38+
3439
__version__ = "0.0.0-auto.0"
3540
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
3641

@@ -45,7 +50,7 @@
4550
NA = "N/A"
4651

4752

48-
def run_test(pins):
53+
def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:
4954

5055
"""
5156
Prints out voltage on the battery monitor or voltage monitor pin.

0 commit comments

Comments
 (0)