Skip to content

Commit 58d7166

Browse files
committed
Add type annotations
1 parent fc0878f commit 58d7166

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

adafruit_servokit.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
import board
3636
from adafruit_pca9685 import PCA9685
3737

38+
try:
39+
from typing import Optional
40+
from busio import I2C
41+
from adafruit_motor.servo import Servo, ContinuousServo
42+
except ImportError:
43+
pass
44+
3845
__version__ = "0.0.0-auto.0"
3946
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ServoKit.git"
4047

@@ -65,12 +72,12 @@ class ServoKit:
6572
def __init__(
6673
self,
6774
*,
68-
channels,
69-
i2c=None,
70-
address=0x40,
71-
reference_clock_speed=25000000,
72-
frequency=50
73-
):
75+
channels: int,
76+
i2c: Optional[I2C] = None,
77+
address: int = 0x40,
78+
reference_clock_speed: int = 25000000,
79+
frequency: int = 50
80+
) -> None:
7481
if channels not in [8, 16]:
7582
raise ValueError("servo_channels must be 8 or 16!")
7683
self._items = [None] * channels
@@ -86,7 +93,7 @@ def __init__(
8693
self._continuous_servo = _ContinuousServo(self)
8794

8895
@property
89-
def servo(self):
96+
def servo(self) -> "_Servo":
9097
""":class:`~adafruit_motor.servo.Servo` controls for standard servos.
9198
9299
This FeatherWing example rotates a servo on channel ``0`` to ``180`` degrees for one second,
@@ -107,7 +114,7 @@ def servo(self):
107114
return self._servo
108115

109116
@property
110-
def continuous_servo(self):
117+
def continuous_servo(self) -> "_ContinuousServo":
111118
""":class:`~adafruit_motor.servo.ContinuousServo` controls for continuous rotation
112119
servos.
113120
@@ -133,10 +140,10 @@ def continuous_servo(self):
133140

134141
class _Servo:
135142
# pylint: disable=protected-access
136-
def __init__(self, kit):
143+
def __init__(self, kit: ServoKit) -> None:
137144
self.kit = kit
138145

139-
def __getitem__(self, servo_channel):
146+
def __getitem__(self, servo_channel: int) -> Servo:
140147
import adafruit_motor.servo # pylint: disable=import-outside-toplevel
141148

142149
num_channels = self.kit._channels
@@ -151,16 +158,16 @@ def __getitem__(self, servo_channel):
151158
return servo
152159
raise ValueError("Channel {} is already in use.".format(servo_channel))
153160

154-
def __len__(self):
161+
def __len__(self) -> int:
155162
return len(self.kit._items)
156163

157164

158165
class _ContinuousServo:
159166
# pylint: disable=protected-access
160-
def __init__(self, kit):
167+
def __init__(self, kit: ServoKit) -> None:
161168
self.kit = kit
162169

163-
def __getitem__(self, servo_channel):
170+
def __getitem__(self, servo_channel: int) -> ContinuousServo:
164171
import adafruit_motor.servo # pylint: disable=import-outside-toplevel
165172

166173
num_channels = self.kit._channels
@@ -179,5 +186,5 @@ def __getitem__(self, servo_channel):
179186
return servo
180187
raise ValueError("Channel {} is already in use.".format(servo_channel))
181188

182-
def __len__(self):
189+
def __len__(self) -> int:
183190
return len(self.kit._items)

0 commit comments

Comments
 (0)