34
34
35
35
try :
36
36
from typing import Type , Any , Union , Optional , Tuple , Sequence , List
37
+
37
38
NotImplementedType = Type [NotImplemented ]
38
39
except ImportError :
39
40
pass
@@ -76,14 +77,18 @@ def _cmp(obj_x: Any, obj_y: Any) -> int:
76
77
return 0 if obj_x == obj_y else 1 if obj_x > obj_y else - 1
77
78
78
79
79
- def _cmperror (obj_x : Union ["datetime" , "timedelta" ], obj_y : Union ["datetime" , "timedelta" ]) -> None :
80
+ def _cmperror (
81
+ obj_x : Union ["datetime" , "timedelta" ], obj_y : Union ["datetime" , "timedelta" ]
82
+ ) -> None :
80
83
raise TypeError (
81
84
"can't compare '%s' to '%s'" % (type (obj_x ).__name__ , type (obj_y ).__name__ )
82
85
)
83
86
84
87
85
88
# Utility functions - time
86
- def _check_time_fields (hour : int , minute : int , second : int , microsecond : int , fold : int ) -> None :
89
+ def _check_time_fields (
90
+ hour : int , minute : int , second : int , microsecond : int , fold : int
91
+ ) -> None :
87
92
if not isinstance (hour , int ):
88
93
raise TypeError ("Hour expected as int" )
89
94
if not 0 <= hour <= 23 :
@@ -200,7 +205,15 @@ def _ymd2ord(year: int, month: int, day: int) -> int:
200
205
201
206
202
207
# pylint: disable=too-many-arguments
203
- def _build_struct_time (tm_year : int , tm_month : int , tm_mday : int , tm_hour : int , tm_min : int , tm_sec : int , tm_isdst : int ) -> _time .struct_time :
208
+ def _build_struct_time (
209
+ tm_year : int ,
210
+ tm_month : int ,
211
+ tm_mday : int ,
212
+ tm_hour : int ,
213
+ tm_min : int ,
214
+ tm_sec : int ,
215
+ tm_isdst : int ,
216
+ ) -> _time .struct_time :
204
217
tm_wday = (_ymd2ord (tm_year , tm_month , tm_mday ) + 6 ) % 7
205
218
tm_yday = _days_before_month (tm_year , tm_month ) + tm_mday
206
219
return _time .struct_time (
@@ -313,7 +326,7 @@ class timedelta:
313
326
def __new__ (
314
327
cls ,
315
328
days : int = 0 ,
316
- seconds :int = 0 ,
329
+ seconds : int = 0 ,
317
330
microseconds : int = 0 ,
318
331
milliseconds : int = 0 ,
319
332
minutes : int = 0 ,
@@ -692,7 +705,12 @@ def today(cls) -> "date":
692
705
return cls .fromtimestamp (_time .time ())
693
706
694
707
# Instance Methods
695
- def replace (self , year : Optional [int ] = None , month : Optional [int ] = None , day : Optional [int ] = None ):
708
+ def replace (
709
+ self ,
710
+ year : Optional [int ] = None ,
711
+ month : Optional [int ] = None ,
712
+ day : Optional [int ] = None ,
713
+ ):
696
714
"""Return a date with the same value, except for those parameters
697
715
given new values by whichever keyword arguments are specified.
698
716
If no keyword arguments are specified - values are obtained from
@@ -799,7 +817,9 @@ class timezone(tzinfo):
799
817
# Sentinel value to disallow None
800
818
_Omitted = object ()
801
819
802
- def __new__ (cls , offset : timedelta , name : Union [str , object ] = _Omitted ) -> "timezone" :
820
+ def __new__ (
821
+ cls , offset : timedelta , name : Union [str , object ] = _Omitted
822
+ ) -> "timezone" :
803
823
if not isinstance (offset , timedelta ):
804
824
raise TypeError ("offset must be a timedelta" )
805
825
if name is cls ._Omitted :
@@ -890,7 +910,16 @@ class time:
890
910
"""
891
911
892
912
# pylint: disable=redefined-outer-name
893
- def __new__ (cls , hour : int = 0 , minute : int = 0 , second : int = 0 , microsecond : int = 0 , tzinfo : Optional [tzinfo ] = None , * , fold : int = 0 ) -> "time" :
913
+ def __new__ (
914
+ cls ,
915
+ hour : int = 0 ,
916
+ minute : int = 0 ,
917
+ second : int = 0 ,
918
+ microsecond : int = 0 ,
919
+ tzinfo : Optional [tzinfo ] = None ,
920
+ * ,
921
+ fold : int = 0
922
+ ) -> "time" :
894
923
_check_time_fields (hour , minute , second , microsecond , fold )
895
924
_check_tzinfo_arg (tzinfo )
896
925
self = object .__new__ (cls )
@@ -1330,7 +1359,9 @@ def _fromtimestamp(cls, t: float, utc: bool, tz: Optional["tzinfo"]) -> "datetim
1330
1359
1331
1360
## pylint: disable=arguments-differ
1332
1361
@classmethod
1333
- def fromtimestamp (cls , timestamp : float , tz : Optional ["tzinfo" ] = None ) -> "datetime" :
1362
+ def fromtimestamp (
1363
+ cls , timestamp : float , tz : Optional ["tzinfo" ] = None
1364
+ ) -> "datetime" :
1334
1365
return cls ._fromtimestamp (timestamp , tz is not None , tz )
1335
1366
1336
1367
@classmethod
@@ -1357,7 +1388,7 @@ def fromisoformat(cls, date_string: str) -> "datetime":
1357
1388
return cls .combine (dateval , timeval )
1358
1389
1359
1390
@classmethod
1360
- def now (cls , timezone : Optional ["tzinfo" ]= None ) -> "datetime" :
1391
+ def now (cls , timezone : Optional ["tzinfo" ] = None ) -> "datetime" :
1361
1392
"""Return the current local date and time."""
1362
1393
return cls .fromtimestamp (_time .time (), tz = timezone )
1363
1394
0 commit comments