Skip to content

Commit 0a14e5f

Browse files
committed
Add type annotations for time
1 parent f4c4724 commit 0a14e5f

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

adafruit_datetime.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from micropython import const
3434

3535
try:
36-
from typing import Type, Any, Union, Optional, Tuple
36+
from typing import Type, Any, Union, Optional, Tuple, Sequence, List
3737
NotImplementedType = Type[NotImplemented]
3838
except ImportError:
3939
pass
@@ -890,7 +890,7 @@ class time:
890890
"""
891891

892892
# pylint: disable=redefined-outer-name
893-
def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0):
893+
def __new__(cls, hour: int = 0, minute: int = 0, second: int = 0, microsecond: int = 0, tzinfo: Optional[tzinfo] = None, *, fold: int = 0) -> "time":
894894
_check_time_fields(hour, minute, second, microsecond, fold)
895895
_check_tzinfo_arg(tzinfo)
896896
self = object.__new__(cls)
@@ -905,39 +905,39 @@ def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold
905905

906906
# Instance attributes (read-only)
907907
@property
908-
def hour(self):
908+
def hour(self) -> int:
909909
"""In range(24)."""
910910
return self._hour
911911

912912
@property
913-
def minute(self):
913+
def minute(self) -> int:
914914
"""In range(60)."""
915915
return self._minute
916916

917917
@property
918-
def second(self):
918+
def second(self) -> int:
919919
"""In range(60)."""
920920
return self._second
921921

922922
@property
923-
def microsecond(self):
923+
def microsecond(self) -> int:
924924
"""In range(1000000)."""
925925
return self._microsecond
926926

927927
@property
928-
def fold(self):
928+
def fold(self) -> int:
929929
"""Fold."""
930930
return self._fold
931931

932932
@property
933-
def tzinfo(self):
933+
def tzinfo(self) -> Optional[tzinfo]:
934934
"""The object passed as the tzinfo argument to
935935
the time constructor, or None if none was passed.
936936
"""
937937
return self._tzinfo
938938

939939
@staticmethod
940-
def _parse_iso_string(string_to_parse, segments):
940+
def _parse_iso_string(string_to_parse: str, segments: Sequence[str]) -> List[int]:
941941
results = []
942942

943943
remaining_string = string_to_parse
@@ -955,7 +955,7 @@ def _parse_iso_string(string_to_parse, segments):
955955

956956
# pylint: disable=too-many-locals
957957
@classmethod
958-
def fromisoformat(cls, time_string):
958+
def fromisoformat(cls, time_string: str) -> "time":
959959
"""Return a time object constructed from an ISO date format.
960960
Valid format is ``HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]``
961961
@@ -1027,7 +1027,7 @@ def fromisoformat(cls, time_string):
10271027
# pylint: enable=too-many-locals
10281028

10291029
# Instance methods
1030-
def isoformat(self, timespec="auto"):
1030+
def isoformat(self, timespec: str = "auto") -> str:
10311031
"""Return a string representing the time in ISO 8601 format, one of:
10321032
HH:MM:SS.ffffff, if microsecond is not 0
10331033
@@ -1049,7 +1049,7 @@ def isoformat(self, timespec="auto"):
10491049
# For a time t, str(t) is equivalent to t.isoformat()
10501050
__str__ = isoformat
10511051

1052-
def utcoffset(self):
1052+
def utcoffset(self) -> timedelta:
10531053
"""Return the timezone offset in minutes east of UTC (negative west of
10541054
UTC)."""
10551055
if self._tzinfo is None:
@@ -1058,7 +1058,7 @@ def utcoffset(self):
10581058
_check_utc_offset("utcoffset", offset)
10591059
return offset
10601060

1061-
def tzname(self):
1061+
def tzname(self) -> str:
10621062
"""Return the timezone name.
10631063
10641064
Note that the name is 100% informational -- there's no requirement that
@@ -1072,32 +1072,32 @@ def tzname(self):
10721072
return name
10731073

10741074
# Standard conversions and comparisons
1075-
def __eq__(self, other):
1075+
def __eq__(self, other: "time") -> bool:
10761076
if not isinstance(other, time):
10771077
return NotImplemented
10781078
return self._cmp(other, allow_mixed=True) == 0
10791079

1080-
def __le__(self, other):
1080+
def __le__(self, other: "time") -> bool:
10811081
if not isinstance(other, time):
10821082
return NotImplemented
10831083
return self._cmp(other) <= 0
10841084

1085-
def __lt__(self, other):
1085+
def __lt__(self, other: "time") -> bool:
10861086
if not isinstance(other, time):
10871087
return NotImplemented
10881088
return self._cmp(other) < 0
10891089

1090-
def __ge__(self, other):
1090+
def __ge__(self, other: "time") -> bool:
10911091
if not isinstance(other, time):
10921092
return NotImplemented
10931093
return self._cmp(other) >= 0
10941094

1095-
def __gt__(self, other):
1095+
def __gt__(self, other: "time") -> bool:
10961096
if not isinstance(other, time):
10971097
return NotImplemented
10981098
return self._cmp(other) > 0
10991099

1100-
def _cmp(self, other, allow_mixed=False):
1100+
def _cmp(self, other: "time", allow_mixed: bool = False) -> int:
11011101
assert isinstance(other, time)
11021102
mytz = self._tzinfo
11031103
ottz = other.tzinfo
@@ -1126,7 +1126,7 @@ def _cmp(self, other, allow_mixed=False):
11261126
(othhmm, other.second, other.microsecond),
11271127
)
11281128

1129-
def __hash__(self):
1129+
def __hash__(self) -> int:
11301130
"""Hash."""
11311131
if self._hashcode == -1:
11321132
t = self
@@ -1146,7 +1146,7 @@ def __hash__(self):
11461146
self._hashcode = hash((h, m, self.second, self.microsecond))
11471147
return self._hashcode
11481148

1149-
def _tzstr(self, sep=":"):
1149+
def _tzstr(self, sep: str = ":") -> Optional[str]:
11501150
"""Return formatted timezone offset (+xx:xx) or None."""
11511151
off = self.utcoffset()
11521152
if off is not None:
@@ -1162,12 +1162,12 @@ def _tzstr(self, sep=":"):
11621162
off = "%s%02d%s%02d" % (sign, hh, sep, mm)
11631163
return off
11641164

1165-
def __format__(self, fmt):
1165+
def __format__(self, fmt: str) -> str:
11661166
if not isinstance(fmt, str):
11671167
raise TypeError("must be str, not %s" % type(fmt).__name__)
11681168
return str(self)
11691169

1170-
def __repr__(self):
1170+
def __repr__(self) -> str:
11711171
"""Convert to formal string, for repr()."""
11721172
if self._microsecond != 0:
11731173
s = ", %d, %d" % (self._second, self._microsecond)
@@ -1187,7 +1187,7 @@ def __repr__(self):
11871187
return s
11881188

11891189
# Pickle support
1190-
def _getstate(self, protocol=3):
1190+
def _getstate(self, protocol: int = 3) -> Tuple[bytes]:
11911191
us2, us3 = divmod(self._microsecond, 256)
11921192
us1, us2 = divmod(us2, 256)
11931193
h = self._hour

0 commit comments

Comments
 (0)