@@ -65,7 +65,12 @@ class date:
65
65
def isoformat (self ) -> str : ...
66
66
def timetuple (self ) -> struct_time : ...
67
67
def toordinal (self ) -> int : ...
68
- def replace (self , year : int = ..., month : int = ..., day : int = ...) -> date : ...
68
+ if sys .version_info >= (3 , 6 ):
69
+ def replace (self : Self , year : int = ..., month : int = ..., day : int = ...) -> Self : ...
70
+ else :
71
+ # Prior to Python 3.6, the `replace` method always returned `date`, even in subclasses
72
+ def replace (self , year : int = ..., month : int = ..., day : int = ...) -> date : ...
73
+
69
74
def __le__ (self , __other : date ) -> bool : ...
70
75
def __lt__ (self , __other : date ) -> bool : ...
71
76
def __ge__ (self , __other : date ) -> bool : ...
@@ -139,16 +144,29 @@ class time:
139
144
def utcoffset (self ) -> timedelta | None : ...
140
145
def tzname (self ) -> str | None : ...
141
146
def dst (self ) -> timedelta | None : ...
142
- def replace (
143
- self ,
144
- hour : int = ...,
145
- minute : int = ...,
146
- second : int = ...,
147
- microsecond : int = ...,
148
- tzinfo : _tzinfo | None = ...,
149
- * ,
150
- fold : int = ...,
151
- ) -> time : ...
147
+ if sys .version_info >= (3 , 6 ):
148
+ def replace (
149
+ self : Self ,
150
+ hour : int = ...,
151
+ minute : int = ...,
152
+ second : int = ...,
153
+ microsecond : int = ...,
154
+ tzinfo : _tzinfo | None = ...,
155
+ * ,
156
+ fold : int = ...,
157
+ ) -> Self : ...
158
+ else :
159
+ # Prior to Python 3.6, the `replace` method always returned `time`, even in subclasses
160
+ def replace (
161
+ self ,
162
+ hour : int = ...,
163
+ minute : int = ...,
164
+ second : int = ...,
165
+ microsecond : int = ...,
166
+ tzinfo : _tzinfo | None = ...,
167
+ * ,
168
+ fold : int = ...,
169
+ ) -> time : ...
152
170
153
171
_date = date
154
172
_time = time
@@ -260,19 +278,35 @@ class datetime(date):
260
278
def date (self ) -> _date : ...
261
279
def time (self ) -> _time : ...
262
280
def timetz (self ) -> _time : ...
263
- def replace (
264
- self ,
265
- year : int = ...,
266
- month : int = ...,
267
- day : int = ...,
268
- hour : int = ...,
269
- minute : int = ...,
270
- second : int = ...,
271
- microsecond : int = ...,
272
- tzinfo : _tzinfo | None = ...,
273
- * ,
274
- fold : int = ...,
275
- ) -> datetime : ...
281
+ if sys .version_info >= (3 , 6 ):
282
+ def replace (
283
+ self : Self ,
284
+ year : int = ...,
285
+ month : int = ...,
286
+ day : int = ...,
287
+ hour : int = ...,
288
+ minute : int = ...,
289
+ second : int = ...,
290
+ microsecond : int = ...,
291
+ tzinfo : _tzinfo | None = ...,
292
+ * ,
293
+ fold : int = ...,
294
+ ) -> Self : ...
295
+ else :
296
+ # Prior to Python 3.6, the `replace` method always returned `datetime`, even in subclasses
297
+ def replace (
298
+ self ,
299
+ year : int = ...,
300
+ month : int = ...,
301
+ day : int = ...,
302
+ hour : int = ...,
303
+ minute : int = ...,
304
+ second : int = ...,
305
+ microsecond : int = ...,
306
+ tzinfo : _tzinfo | None = ...,
307
+ * ,
308
+ fold : int = ...,
309
+ ) -> datetime : ...
276
310
if sys .version_info >= (3 , 8 ):
277
311
def astimezone (self : Self , tz : _tzinfo | None = ...) -> Self : ...
278
312
else :
0 commit comments