Skip to content

Commit c985902

Browse files
committed
[stdlib] Restrict timespec parameter in datetime.{date,}time.isoformat
Only certain values are allowed according to the documentation.
1 parent 8e21ebd commit c985902

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎stdlib/datetime.pyi‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from abc import abstractmethod
33
from time import struct_time
4-
from typing import Any, ClassVar, Final, Generic, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only
4+
from typing import Any, ClassVar, Final, Generic, Literal, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only
55
from typing_extensions import CapsuleType, Never, Self, deprecated, disjoint_base
66

77
if sys.version_info >= (3, 11):
@@ -158,7 +158,9 @@ class time:
158158
def __gt__(self, value: time, /) -> bool: ...
159159
def __eq__(self, value: object, /) -> bool: ...
160160
def __hash__(self) -> int: ...
161-
def isoformat(self, timespec: str = "auto") -> str: ...
161+
def isoformat(
162+
self, timespec: Literal["auto", "hours", "minutes", "seconds", "milliseconds", "microseconds"] = "auto"
163+
) -> str: ...
162164

163165
if sys.version_info >= (3, 15):
164166
@classmethod
@@ -479,7 +481,9 @@ class datetime(date, Generic[_TzInfoT]):
479481
) -> datetime[None]: ...
480482

481483
def astimezone(self, tz: _TzInfo | None = None) -> datetime[_TzInfo]: ...
482-
def isoformat(self, sep: str = "T", timespec: str = "auto") -> str: ...
484+
def isoformat(
485+
self, sep: str = "T", timespec: Literal["auto", "hours", "minutes", "seconds", "milliseconds", "microseconds"] = "auto"
486+
) -> str: ...
483487

484488
if sys.version_info >= (3, 15):
485489
@classmethod

0 commit comments

Comments
 (0)