33
33
from micropython import const
34
34
35
35
try :
36
- from typing import Type , Any , Union , Optional , Tuple
36
+ from typing import Type , Any , Union , Optional , Tuple , Sequence , List
37
37
NotImplementedType = Type [NotImplemented ]
38
38
except ImportError :
39
39
pass
@@ -890,7 +890,7 @@ class time:
890
890
"""
891
891
892
892
# 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" :
894
894
_check_time_fields (hour , minute , second , microsecond , fold )
895
895
_check_tzinfo_arg (tzinfo )
896
896
self = object .__new__ (cls )
@@ -905,39 +905,39 @@ def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold
905
905
906
906
# Instance attributes (read-only)
907
907
@property
908
- def hour (self ):
908
+ def hour (self ) -> int :
909
909
"""In range(24)."""
910
910
return self ._hour
911
911
912
912
@property
913
- def minute (self ):
913
+ def minute (self ) -> int :
914
914
"""In range(60)."""
915
915
return self ._minute
916
916
917
917
@property
918
- def second (self ):
918
+ def second (self ) -> int :
919
919
"""In range(60)."""
920
920
return self ._second
921
921
922
922
@property
923
- def microsecond (self ):
923
+ def microsecond (self ) -> int :
924
924
"""In range(1000000)."""
925
925
return self ._microsecond
926
926
927
927
@property
928
- def fold (self ):
928
+ def fold (self ) -> int :
929
929
"""Fold."""
930
930
return self ._fold
931
931
932
932
@property
933
- def tzinfo (self ):
933
+ def tzinfo (self ) -> Optional [ tzinfo ] :
934
934
"""The object passed as the tzinfo argument to
935
935
the time constructor, or None if none was passed.
936
936
"""
937
937
return self ._tzinfo
938
938
939
939
@staticmethod
940
- def _parse_iso_string (string_to_parse , segments ) :
940
+ def _parse_iso_string (string_to_parse : str , segments : Sequence [ str ]) -> List [ int ] :
941
941
results = []
942
942
943
943
remaining_string = string_to_parse
@@ -955,7 +955,7 @@ def _parse_iso_string(string_to_parse, segments):
955
955
956
956
# pylint: disable=too-many-locals
957
957
@classmethod
958
- def fromisoformat (cls , time_string ) :
958
+ def fromisoformat (cls , time_string : str ) -> "time" :
959
959
"""Return a time object constructed from an ISO date format.
960
960
Valid format is ``HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]``
961
961
@@ -1027,7 +1027,7 @@ def fromisoformat(cls, time_string):
1027
1027
# pylint: enable=too-many-locals
1028
1028
1029
1029
# Instance methods
1030
- def isoformat (self , timespec = "auto" ):
1030
+ def isoformat (self , timespec : str = "auto" ) -> str :
1031
1031
"""Return a string representing the time in ISO 8601 format, one of:
1032
1032
HH:MM:SS.ffffff, if microsecond is not 0
1033
1033
@@ -1049,7 +1049,7 @@ def isoformat(self, timespec="auto"):
1049
1049
# For a time t, str(t) is equivalent to t.isoformat()
1050
1050
__str__ = isoformat
1051
1051
1052
- def utcoffset (self ):
1052
+ def utcoffset (self ) -> timedelta :
1053
1053
"""Return the timezone offset in minutes east of UTC (negative west of
1054
1054
UTC)."""
1055
1055
if self ._tzinfo is None :
@@ -1058,7 +1058,7 @@ def utcoffset(self):
1058
1058
_check_utc_offset ("utcoffset" , offset )
1059
1059
return offset
1060
1060
1061
- def tzname (self ):
1061
+ def tzname (self ) -> str :
1062
1062
"""Return the timezone name.
1063
1063
1064
1064
Note that the name is 100% informational -- there's no requirement that
@@ -1072,32 +1072,32 @@ def tzname(self):
1072
1072
return name
1073
1073
1074
1074
# Standard conversions and comparisons
1075
- def __eq__ (self , other ) :
1075
+ def __eq__ (self , other : "time" ) -> bool :
1076
1076
if not isinstance (other , time ):
1077
1077
return NotImplemented
1078
1078
return self ._cmp (other , allow_mixed = True ) == 0
1079
1079
1080
- def __le__ (self , other ) :
1080
+ def __le__ (self , other : "time" ) -> bool :
1081
1081
if not isinstance (other , time ):
1082
1082
return NotImplemented
1083
1083
return self ._cmp (other ) <= 0
1084
1084
1085
- def __lt__ (self , other ) :
1085
+ def __lt__ (self , other : "time" ) -> bool :
1086
1086
if not isinstance (other , time ):
1087
1087
return NotImplemented
1088
1088
return self ._cmp (other ) < 0
1089
1089
1090
- def __ge__ (self , other ) :
1090
+ def __ge__ (self , other : "time" ) -> bool :
1091
1091
if not isinstance (other , time ):
1092
1092
return NotImplemented
1093
1093
return self ._cmp (other ) >= 0
1094
1094
1095
- def __gt__ (self , other ) :
1095
+ def __gt__ (self , other : "time" ) -> bool :
1096
1096
if not isinstance (other , time ):
1097
1097
return NotImplemented
1098
1098
return self ._cmp (other ) > 0
1099
1099
1100
- def _cmp (self , other , allow_mixed = False ):
1100
+ def _cmp (self , other : "time" , allow_mixed : bool = False ) -> int :
1101
1101
assert isinstance (other , time )
1102
1102
mytz = self ._tzinfo
1103
1103
ottz = other .tzinfo
@@ -1126,7 +1126,7 @@ def _cmp(self, other, allow_mixed=False):
1126
1126
(othhmm , other .second , other .microsecond ),
1127
1127
)
1128
1128
1129
- def __hash__ (self ):
1129
+ def __hash__ (self ) -> int :
1130
1130
"""Hash."""
1131
1131
if self ._hashcode == - 1 :
1132
1132
t = self
@@ -1146,7 +1146,7 @@ def __hash__(self):
1146
1146
self ._hashcode = hash ((h , m , self .second , self .microsecond ))
1147
1147
return self ._hashcode
1148
1148
1149
- def _tzstr (self , sep = ":" ):
1149
+ def _tzstr (self , sep : str = ":" ) -> Optional [ str ] :
1150
1150
"""Return formatted timezone offset (+xx:xx) or None."""
1151
1151
off = self .utcoffset ()
1152
1152
if off is not None :
@@ -1162,12 +1162,12 @@ def _tzstr(self, sep=":"):
1162
1162
off = "%s%02d%s%02d" % (sign , hh , sep , mm )
1163
1163
return off
1164
1164
1165
- def __format__ (self , fmt ) :
1165
+ def __format__ (self , fmt : str ) -> str :
1166
1166
if not isinstance (fmt , str ):
1167
1167
raise TypeError ("must be str, not %s" % type (fmt ).__name__ )
1168
1168
return str (self )
1169
1169
1170
- def __repr__ (self ):
1170
+ def __repr__ (self ) -> str :
1171
1171
"""Convert to formal string, for repr()."""
1172
1172
if self ._microsecond != 0 :
1173
1173
s = ", %d, %d" % (self ._second , self ._microsecond )
@@ -1187,7 +1187,7 @@ def __repr__(self):
1187
1187
return s
1188
1188
1189
1189
# Pickle support
1190
- def _getstate (self , protocol = 3 ) :
1190
+ def _getstate (self , protocol : int = 3 ) -> Tuple [ bytes ] :
1191
1191
us2 , us3 = divmod (self ._microsecond , 256 )
1192
1192
us1 , us2 = divmod (us2 , 256 )
1193
1193
h = self ._hour
0 commit comments