Skip to content

Commit 130ba2e

Browse files
Support SupportsIndex in constructors for all datetime objects (#9915)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b6564d9 commit 130ba2e

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

stdlib/datetime.pyi

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from abc import abstractmethod
33
from time import struct_time
44
from typing import ClassVar, NamedTuple, NoReturn, TypeVar, overload
5-
from typing_extensions import Literal, Self, TypeAlias, final
5+
from typing_extensions import Literal, Self, SupportsIndex, TypeAlias, final
66

77
if sys.version_info >= (3, 11):
88
__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC")
@@ -49,7 +49,7 @@ class date:
4949
min: ClassVar[date]
5050
max: ClassVar[date]
5151
resolution: ClassVar[timedelta]
52-
def __new__(cls, year: int, month: int, day: int) -> Self: ...
52+
def __new__(cls, year: SupportsIndex, month: SupportsIndex, day: SupportsIndex) -> Self: ...
5353
@classmethod
5454
def fromtimestamp(cls, __timestamp: float) -> Self: ...
5555
@classmethod
@@ -81,7 +81,7 @@ class date:
8181
def isoformat(self) -> str: ...
8282
def timetuple(self) -> struct_time: ...
8383
def toordinal(self) -> int: ...
84-
def replace(self, year: int = ..., month: int = ..., day: int = ...) -> Self: ...
84+
def replace(self, year: SupportsIndex = ..., month: SupportsIndex = ..., day: SupportsIndex = ...) -> Self: ...
8585
def __le__(self, __value: date) -> bool: ...
8686
def __lt__(self, __value: date) -> bool: ...
8787
def __ge__(self, __value: date) -> bool: ...
@@ -119,10 +119,10 @@ class time:
119119
resolution: ClassVar[timedelta]
120120
def __new__(
121121
cls,
122-
hour: int = ...,
123-
minute: int = ...,
124-
second: int = ...,
125-
microsecond: int = ...,
122+
hour: SupportsIndex = ...,
123+
minute: SupportsIndex = ...,
124+
second: SupportsIndex = ...,
125+
microsecond: SupportsIndex = ...,
126126
tzinfo: _TzInfo | None = ...,
127127
*,
128128
fold: int = ...,
@@ -160,10 +160,10 @@ class time:
160160
def dst(self) -> timedelta | None: ...
161161
def replace(
162162
self,
163-
hour: int = ...,
164-
minute: int = ...,
165-
second: int = ...,
166-
microsecond: int = ...,
163+
hour: SupportsIndex = ...,
164+
minute: SupportsIndex = ...,
165+
second: SupportsIndex = ...,
166+
microsecond: SupportsIndex = ...,
167167
tzinfo: _TzInfo | None = ...,
168168
*,
169169
fold: int = ...,
@@ -223,13 +223,13 @@ class datetime(date):
223223
max: ClassVar[datetime]
224224
def __new__(
225225
cls,
226-
year: int,
227-
month: int,
228-
day: int,
229-
hour: int = ...,
230-
minute: int = ...,
231-
second: int = ...,
232-
microsecond: int = ...,
226+
year: SupportsIndex,
227+
month: SupportsIndex,
228+
day: SupportsIndex,
229+
hour: SupportsIndex = ...,
230+
minute: SupportsIndex = ...,
231+
second: SupportsIndex = ...,
232+
microsecond: SupportsIndex = ...,
233233
tzinfo: _TzInfo | None = ...,
234234
*,
235235
fold: int = ...,
@@ -280,13 +280,13 @@ class datetime(date):
280280
def timetz(self) -> _Time: ...
281281
def replace(
282282
self,
283-
year: int = ...,
284-
month: int = ...,
285-
day: int = ...,
286-
hour: int = ...,
287-
minute: int = ...,
288-
second: int = ...,
289-
microsecond: int = ...,
283+
year: SupportsIndex = ...,
284+
month: SupportsIndex = ...,
285+
day: SupportsIndex = ...,
286+
hour: SupportsIndex = ...,
287+
minute: SupportsIndex = ...,
288+
second: SupportsIndex = ...,
289+
microsecond: SupportsIndex = ...,
290290
tzinfo: _TzInfo | None = ...,
291291
*,
292292
fold: int = ...,

0 commit comments

Comments
 (0)