Skip to content

Support SupportsIndex in constructors for all datetime objects #9915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions stdlib/datetime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sys
from abc import abstractmethod
from time import struct_time
from typing import ClassVar, NamedTuple, NoReturn, TypeVar, overload
from typing_extensions import Literal, Self, TypeAlias, final
from typing_extensions import Literal, Self, SupportsIndex, TypeAlias, final

if sys.version_info >= (3, 11):
__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC")
Expand Down Expand Up @@ -49,7 +49,7 @@ class date:
min: ClassVar[date]
max: ClassVar[date]
resolution: ClassVar[timedelta]
def __new__(cls, year: int, month: int, day: int) -> Self: ...
def __new__(cls, year: SupportsIndex, month: SupportsIndex, day: SupportsIndex) -> Self: ...
@classmethod
def fromtimestamp(cls, __timestamp: float) -> Self: ...
@classmethod
Expand Down Expand Up @@ -81,7 +81,7 @@ class date:
def isoformat(self) -> str: ...
def timetuple(self) -> struct_time: ...
def toordinal(self) -> int: ...
def replace(self, year: int = ..., month: int = ..., day: int = ...) -> Self: ...
def replace(self, year: SupportsIndex = ..., month: SupportsIndex = ..., day: SupportsIndex = ...) -> Self: ...
def __le__(self, __value: date) -> bool: ...
def __lt__(self, __value: date) -> bool: ...
def __ge__(self, __value: date) -> bool: ...
Expand Down Expand Up @@ -119,10 +119,10 @@ class time:
resolution: ClassVar[timedelta]
def __new__(
cls,
hour: int = ...,
minute: int = ...,
second: int = ...,
microsecond: int = ...,
hour: SupportsIndex = ...,
minute: SupportsIndex = ...,
second: SupportsIndex = ...,
microsecond: SupportsIndex = ...,
tzinfo: _TzInfo | None = ...,
*,
fold: int = ...,
Expand Down Expand Up @@ -160,10 +160,10 @@ class time:
def dst(self) -> timedelta | None: ...
def replace(
self,
hour: int = ...,
minute: int = ...,
second: int = ...,
microsecond: int = ...,
hour: SupportsIndex = ...,
minute: SupportsIndex = ...,
second: SupportsIndex = ...,
microsecond: SupportsIndex = ...,
tzinfo: _TzInfo | None = ...,
*,
fold: int = ...,
Expand Down Expand Up @@ -223,13 +223,13 @@ class datetime(date):
max: ClassVar[datetime]
def __new__(
cls,
year: int,
month: int,
day: int,
hour: int = ...,
minute: int = ...,
second: int = ...,
microsecond: int = ...,
year: SupportsIndex,
month: SupportsIndex,
day: SupportsIndex,
hour: SupportsIndex = ...,
minute: SupportsIndex = ...,
second: SupportsIndex = ...,
microsecond: SupportsIndex = ...,
tzinfo: _TzInfo | None = ...,
*,
fold: int = ...,
Expand Down Expand Up @@ -280,13 +280,13 @@ class datetime(date):
def timetz(self) -> _Time: ...
def replace(
self,
year: int = ...,
month: int = ...,
day: int = ...,
hour: int = ...,
minute: int = ...,
second: int = ...,
microsecond: int = ...,
year: SupportsIndex = ...,
month: SupportsIndex = ...,
day: SupportsIndex = ...,
hour: SupportsIndex = ...,
minute: SupportsIndex = ...,
second: SupportsIndex = ...,
microsecond: SupportsIndex = ...,
tzinfo: _TzInfo | None = ...,
*,
fold: int = ...,
Expand Down