Skip to content

Commit f7d9476

Browse files
authored
Merge pull request #43 from tekktrik/doc/add-typing
Add type annotations
2 parents 62a5015 + ff88c97 commit f7d9476

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

adafruit_motorkit.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
import board
3838
from adafruit_pca9685 import PCA9685
3939

40+
try:
41+
from typing import Optional, Tuple
42+
from busio import I2C
43+
import adafruit_motor.motor
44+
import adafruit_motor.stepper
45+
except ImportError:
46+
pass
47+
4048
__version__ = "0.0.0-auto.0"
4149
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MotorKit.git"
4250

@@ -50,8 +58,12 @@ class MotorKit:
5058
Alternately, if using with multiple I2C devices, you can specify the I2C bus."""
5159

5260
def __init__(
53-
self, address=0x60, i2c=None, steppers_microsteps=16, pwm_frequency=1600
54-
):
61+
self,
62+
address: int = 0x60,
63+
i2c: Optional[I2C] = None,
64+
steppers_microsteps: int = 16,
65+
pwm_frequency: float = 1600.0,
66+
) -> None:
5567
self._motor1 = None
5668
self._motor2 = None
5769
self._motor3 = None
@@ -67,7 +79,9 @@ def __init__(
6779
# We can save memory usage (~300 bytes) by deduplicating the construction of the objects for
6880
# each motor. This saves both code size and the number of raw strings (the error message)
6981
# stored. The same technique is a net loss for stepper because there is less duplication.
70-
def _motor(self, motor_name, channels, stepper_name):
82+
def _motor(
83+
self, motor_name: int, channels: Tuple[int, int, int], stepper_name: int
84+
) -> adafruit_motor.motor.DCMotor:
7185
from adafruit_motor import motor # pylint: disable=import-outside-toplevel
7286

7387
motor_name = "_motor" + str(motor_name)
@@ -90,7 +104,7 @@ def _motor(self, motor_name, channels, stepper_name):
90104
return getattr(self, motor_name)
91105

92106
@property
93-
def motor1(self):
107+
def motor1(self) -> adafruit_motor.motor.DCMotor:
94108
""":py:class:``~adafruit_motor.motor.DCMotor`` controls for motor 1.
95109
96110
The following image shows the location of the M1 terminal on the DC/Stepper FeatherWing.
@@ -117,7 +131,7 @@ def motor1(self):
117131
return self._motor(1, (8, 9, 10), 1)
118132

119133
@property
120-
def motor2(self):
134+
def motor2(self) -> adafruit_motor.motor.DCMotor:
121135
""":py:class:``~adafruit_motor.motor.DCMotor`` controls for motor 2.
122136
123137
The following image shows the location of the M2 terminal on the DC/Stepper FeatherWing.
@@ -144,7 +158,7 @@ def motor2(self):
144158
return self._motor(2, (13, 11, 12), 1)
145159

146160
@property
147-
def motor3(self):
161+
def motor3(self) -> adafruit_motor.motor.DCMotor:
148162
""":py:class:``~adafruit_motor.motor.DCMotor`` controls for motor 3.
149163
150164
The following image shows the location of the M2 terminal on the DC/Stepper FeatherWing.
@@ -171,7 +185,7 @@ def motor3(self):
171185
return self._motor(3, (2, 3, 4), 2)
172186

173187
@property
174-
def motor4(self):
188+
def motor4(self) -> adafruit_motor.motor.DCMotor:
175189
""":py:class:``~adafruit_motor.motor.DCMotor`` controls for motor 4.
176190
177191
.. image :: ../docs/_static/motor_featherwing/m4.jpg
@@ -194,7 +208,7 @@ def motor4(self):
194208
return self._motor(4, (7, 5, 6), 2)
195209

196210
@property
197-
def stepper1(self):
211+
def stepper1(self) -> adafruit_motor.stepper.StepperMotor:
198212
""":py:class:``~adafruit_motor.stepper.StepperMotor`` controls for one connected to stepper
199213
1 (also labeled motor 1 and motor 2).
200214
@@ -238,7 +252,7 @@ def stepper1(self):
238252
return self._stepper1
239253

240254
@property
241-
def stepper2(self):
255+
def stepper2(self) -> adafruit_motor.stepper.StepperMotor:
242256
""":py:class:``~adafruit_motor.stepper.StepperMotor`` controls for one connected to stepper
243257
2 (also labeled motor 3 and motor 4).
244258
@@ -282,10 +296,10 @@ def stepper2(self):
282296
return self._stepper2
283297

284298
@property
285-
def frequency(self):
299+
def frequency(self) -> float:
286300
"""The overall PCA9685 PWM frequency in Hertz."""
287301
return self._pca.frequency
288302

289303
@frequency.setter
290-
def frequency(self, pwm_frequency=1600):
304+
def frequency(self, pwm_frequency: float = 1600.0) -> None:
291305
self._pca.frequency = pwm_frequency

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Uncomment the below if you use native CircuitPython modules such as
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
28-
# autodoc_mock_imports = ["digitalio", "busio"]
28+
autodoc_mock_imports = ["pwmio"]
2929

3030

3131
intersphinx_mapping = {

0 commit comments

Comments
 (0)