From 76a42727abd8485fc9a2af2e711d583be26627bf Mon Sep 17 00:00:00 2001 From: funkyrailroad Date: Thu, 23 May 2024 11:56:09 -0400 Subject: [PATCH] Add datetime `__replace__` methods on 3.13+ (#12014) --- stdlib/@tests/stubtest_allowlists/py313.txt | 3 -- stdlib/datetime.pyi | 32 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index f13eb48c1..f225bf6e0 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -178,11 +178,8 @@ ctypes.sizeof ctypes.wintypes.PCHAR.from_param ctypes.wintypes.PWCHAR.from_param dataclasses.Field.__class_getitem__ -datetime.date.__replace__ datetime.date.fromisoformat -datetime.datetime.__replace__ datetime.datetime.fromisoformat -datetime.time.__replace__ datetime.time.fromisoformat datetime.timezone.dst datetime.timezone.fromutc diff --git a/stdlib/datetime.pyi b/stdlib/datetime.pyi index 7b890ca01..71522a59d 100644 --- a/stdlib/datetime.pyi +++ b/stdlib/datetime.pyi @@ -79,6 +79,9 @@ class date: def isoformat(self) -> str: ... def timetuple(self) -> struct_time: ... def toordinal(self) -> int: ... + if sys.version_info >= (3, 13): + def __replace__(self, /, *, year: SupportsIndex = ..., month: SupportsIndex = ..., day: SupportsIndex = ...) -> Self: ... + def replace(self, year: SupportsIndex = ..., month: SupportsIndex = ..., day: SupportsIndex = ...) -> Self: ... def __le__(self, value: date, /) -> bool: ... def __lt__(self, value: date, /) -> bool: ... @@ -148,6 +151,19 @@ class time: def utcoffset(self) -> timedelta | None: ... def tzname(self) -> str | None: ... def dst(self) -> timedelta | None: ... + if sys.version_info >= (3, 13): + def __replace__( + self, + /, + *, + hour: SupportsIndex = ..., + minute: SupportsIndex = ..., + second: SupportsIndex = ..., + microsecond: SupportsIndex = ..., + tzinfo: _TzInfo | None = ..., + fold: int = ..., + ) -> Self: ... + def replace( self, hour: SupportsIndex = ..., @@ -263,6 +279,22 @@ class datetime(date): def date(self) -> _Date: ... def time(self) -> _Time: ... def timetz(self) -> _Time: ... + if sys.version_info >= (3, 13): + def __replace__( + self, + /, + *, + year: SupportsIndex = ..., + month: SupportsIndex = ..., + day: SupportsIndex = ..., + hour: SupportsIndex = ..., + minute: SupportsIndex = ..., + second: SupportsIndex = ..., + microsecond: SupportsIndex = ..., + tzinfo: _TzInfo | None = ..., + fold: int = ..., + ) -> Self: ... + def replace( self, year: SupportsIndex = ...,