From a32d24cae09f32d8a33c8ceb2dfb8294c1d8b075 Mon Sep 17 00:00:00 2001 From: scaramallion Date: Wed, 26 May 2021 18:00:37 +1000 Subject: [PATCH] Use __new__ for datetime.time (#5530) --- CONTRIBUTING.md | 8 ++++---- stdlib/@python2/datetime.pyi | 11 ++++++++--- stdlib/datetime.pyi | 6 +++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 648b5d832..54433b233 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -274,13 +274,13 @@ MAXYEAR: int MINYEAR: int class date: - def __init__(self, year: int, month: int, day: int) -> None: ... + def __new__(cls: Type[_S], year: int, month: int, day: int) -> _S: ... @classmethod - def fromtimestamp(cls, timestamp: float) -> date: ... + def fromtimestamp(cls: Type[_S], __timestamp: float) -> _S: ... @classmethod - def today(cls) -> date: ... + def today(cls: Type[_S]) -> _S: ... @classmethod - def fromordinal(cls, ordinal: int) -> date: ... + def fromordinal(cls: Type[_S], n: int) -> _S: ... @property def year(self) -> int: ... def replace(self, year: int = ..., month: int = ..., day: int = ...) -> date: ... diff --git a/stdlib/@python2/datetime.pyi b/stdlib/@python2/datetime.pyi index 1cc17167a..cb62d58f4 100644 --- a/stdlib/@python2/datetime.pyi +++ b/stdlib/@python2/datetime.pyi @@ -59,9 +59,14 @@ class time: min: ClassVar[time] max: ClassVar[time] resolution: ClassVar[timedelta] - def __init__( - self, hour: int = ..., minute: int = ..., second: int = ..., microsecond: int = ..., tzinfo: Optional[_tzinfo] = ... - ) -> None: ... + def __new__( + cls: Type[_S], + hour: int = ..., + minute: int = ..., + second: int = ..., + microsecond: int = ..., + tzinfo: Optional[_tzinfo] = ..., + ) -> _S: ... @property def hour(self) -> int: ... @property diff --git a/stdlib/datetime.pyi b/stdlib/datetime.pyi index c46d01265..3bea92243 100644 --- a/stdlib/datetime.pyi +++ b/stdlib/datetime.pyi @@ -85,8 +85,8 @@ class time: min: ClassVar[time] max: ClassVar[time] resolution: ClassVar[timedelta] - def __init__( - self, + def __new__( + cls: Type[_S], hour: int = ..., minute: int = ..., second: int = ..., @@ -94,7 +94,7 @@ class time: tzinfo: Optional[_tzinfo] = ..., *, fold: int = ..., - ) -> None: ... + ) -> _S: ... @property def hour(self) -> int: ... @property