Skip to content

Commit d450a5d

Browse files
authored
Merge pull request #25 from tekktrik/doc/add-typing
Add type annotations
2 parents e743fbb + 2e9c11c commit d450a5d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

adafruit_ds1307.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
from adafruit_register import i2c_bit
4747
from adafruit_register import i2c_bcd_datetime
4848

49+
try:
50+
import typing # pylint: disable=unused-import
51+
from busio import I2C
52+
from time import struct_time
53+
except ImportError:
54+
pass
55+
4956
__version__ = "0.0.0-auto.0"
5057
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DS1307.git"
5158

@@ -94,7 +101,7 @@ class DS1307:
94101
datetime_register = i2c_bcd_datetime.BCDDateTimeRegister(0x00)
95102
"""Current date and time."""
96103

97-
def __init__(self, i2c_bus):
104+
def __init__(self, i2c_bus: I2C) -> None:
98105
self.i2c_device = I2CDevice(i2c_bus, 0x68)
99106

100107
# Try and verify this is the RTC we expect by checking constant fields.
@@ -115,12 +122,12 @@ def __init__(self, i2c_bus):
115122
raise ValueError("Unable to find DS1307 at i2c address 0x68.")
116123

117124
@property
118-
def datetime(self):
125+
def datetime(self) -> struct_time:
119126
"""Gets the current date and time or sets the current date and time then starts the
120127
clock."""
121128
return self.datetime_register
122129

123130
@datetime.setter
124-
def datetime(self, value):
131+
def datetime(self, value: struct_time) -> None:
125132
self.disable_oscillator = False
126133
self.datetime_register = value

0 commit comments

Comments
 (0)