From 96ad09c55919d1ce4844c7f89c422a44b8b6bd8e Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Sun, 2 May 2021 15:39:11 +0200 Subject: [PATCH] fix date.isocalendar() to return namedtuple on py39+ (#5302) --- stdlib/datetime.pyi | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/stdlib/datetime.pyi b/stdlib/datetime.pyi index 5cfb42b32..4692f590b 100644 --- a/stdlib/datetime.pyi +++ b/stdlib/datetime.pyi @@ -1,6 +1,6 @@ import sys from time import struct_time -from typing import AnyStr, ClassVar, Optional, SupportsAbs, Tuple, Type, TypeVar, Union, overload +from typing import AnyStr, ClassVar, NamedTuple, Optional, SupportsAbs, Tuple, Type, TypeVar, Union, overload _S = TypeVar("_S") @@ -26,6 +26,12 @@ if sys.version_info >= (3, 2): def __init__(self, offset: timedelta, name: str = ...) -> None: ... def __hash__(self) -> int: ... +if sys.version_info >= (3, 9): + class _IsoCalendarDate(NamedTuple): + year: int + week: int + weekday: int + _tzinfo = tzinfo class date: @@ -78,7 +84,10 @@ class date: def __hash__(self) -> int: ... def weekday(self) -> int: ... def isoweekday(self) -> int: ... - def isocalendar(self) -> Tuple[int, int, int]: ... + if sys.version_info >= (3, 9): + def isocalendar(self) -> _IsoCalendarDate: ... + else: + def isocalendar(self) -> Tuple[int, int, int]: ... class time: min: ClassVar[time] @@ -370,4 +379,7 @@ class datetime(date): def __hash__(self) -> int: ... def weekday(self) -> int: ... def isoweekday(self) -> int: ... - def isocalendar(self) -> Tuple[int, int, int]: ... + if sys.version_info >= (3, 9): + def isocalendar(self) -> _IsoCalendarDate: ... + else: + def isocalendar(self) -> Tuple[int, int, int]: ...