Skip to content

Add missing __reduce__ and __reduce_ex__ methods to datetime classes #6321

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

Closed
Closed
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
15 changes: 14 additions & 1 deletion stdlib/datetime.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
from _typeshed import Self
from time import struct_time
from typing import ClassVar, NamedTuple, SupportsAbs, Type, TypeVar, overload
from typing_extensions import final
from typing_extensions import SupportsIndex, final

_S = TypeVar("_S")

Expand All @@ -13,6 +14,7 @@ class tzinfo:
def utcoffset(self, dt: datetime | None) -> timedelta | None: ...
def dst(self, dt: datetime | None) -> timedelta | None: ...
def fromutc(self, dt: datetime) -> datetime: ...
def __reduce__(self: Self) -> tuple[Type[Self], tuple[Self]]: ...

# Alias required to avoid name conflicts with date(time).tzinfo.
_tzinfo = tzinfo
Expand Down Expand Up @@ -75,6 +77,11 @@ class date:
def __sub__(self, other: timedelta) -> date: ...
@overload
def __sub__(self, other: date) -> timedelta: ...
def __reduce__(self: Self) -> tuple[Type[Self], tuple[bytes]]: ...
if sys.version_info >= (3, 8):
def __reduce_ex__(self: Self, __protocol: SupportsIndex) -> tuple[Type[Self], tuple[bytes]]: ...
else:
def __reduce_ex__(self: Self, __protocol: int) -> tuple[Type[Self], tuple[bytes]]: ...
def __hash__(self) -> int: ...
def weekday(self) -> int: ...
def isoweekday(self) -> int: ...
Expand Down Expand Up @@ -114,6 +121,11 @@ class time:
def __ge__(self, other: time) -> bool: ...
def __gt__(self, other: time) -> bool: ...
def __hash__(self) -> int: ...
def __reduce__(self: Self) -> tuple[Type[Self], tuple[bytes]]: ...
if sys.version_info >= (3, 8):
def __reduce_ex__(self: Self, __protocol: SupportsIndex) -> tuple[Type[Self], tuple[bytes]]: ...
else:
def __reduce_ex__(self: Self, __protocol: int) -> tuple[Type[Self], tuple[bytes]]: ...
def isoformat(self, timespec: str = ...) -> str: ...
if sys.version_info >= (3, 7):
@classmethod
Expand Down Expand Up @@ -183,6 +195,7 @@ class timedelta(SupportsAbs[timedelta]):
def __gt__(self, other: timedelta) -> bool: ...
def __bool__(self) -> bool: ...
def __hash__(self) -> int: ...
def __reduce__(self: Self) -> tuple[Type[Self], tuple[int, int, int]]: ...

class datetime(date):
min: ClassVar[datetime]
Expand Down