diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 9693f18e2e05d..ecddd83322bbf 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -21,7 +21,7 @@ from pandas._libs.tslibs import ( Timedelta, ) -_S = TypeVar("_S", bound=datetime) +_DatetimeT = TypeVar("_DatetimeT", bound=datetime) def integer_op_not_supported(obj: object) -> TypeError: ... @@ -34,7 +34,7 @@ class Timestamp(datetime): # error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]") def __new__( # type: ignore[misc] - cls: type[_S], + cls: type[_DatetimeT], ts_input: int | np.integer | float @@ -56,7 +56,7 @@ class Timestamp(datetime): tzinfo: _tzinfo | None = ..., *, fold: int | None = ..., - ) -> _S | NaTType: ... + ) -> _DatetimeT | NaTType: ... def _set_freq(self, freq: BaseOffset | None) -> None: ... @property def year(self) -> int: ... @@ -79,27 +79,29 @@ class Timestamp(datetime): @property def fold(self) -> int: ... @classmethod - def fromtimestamp(cls: type[_S], t: float, tz: _tzinfo | None = ...) -> _S: ... + def fromtimestamp( + cls: type[_DatetimeT], t: float, tz: _tzinfo | None = ... + ) -> _DatetimeT: ... @classmethod - def utcfromtimestamp(cls: type[_S], t: float) -> _S: ... + def utcfromtimestamp(cls: type[_DatetimeT], t: float) -> _DatetimeT: ... @classmethod - def today(cls: type[_S], tz: _tzinfo | str | None = ...) -> _S: ... + def today(cls: type[_DatetimeT], tz: _tzinfo | str | None = ...) -> _DatetimeT: ... @classmethod def fromordinal( - cls: type[_S], + cls: type[_DatetimeT], ordinal: int, freq: str | BaseOffset | None = ..., tz: _tzinfo | str | None = ..., - ) -> _S: ... + ) -> _DatetimeT: ... @classmethod - def now(cls: type[_S], tz: _tzinfo | str | None = ...) -> _S: ... + def now(cls: type[_DatetimeT], tz: _tzinfo | str | None = ...) -> _DatetimeT: ... @classmethod - def utcnow(cls: type[_S]) -> _S: ... + def utcnow(cls: type[_DatetimeT]) -> _DatetimeT: ... # error: Signature of "combine" incompatible with supertype "datetime" @classmethod def combine(cls, date: _date, time: _time) -> datetime: ... # type: ignore[override] @classmethod - def fromisoformat(cls: type[_S], date_string: str) -> _S: ... + def fromisoformat(cls: type[_DatetimeT], date_string: str) -> _DatetimeT: ... def strftime(self, format: str) -> str: ... def __format__(self, fmt: str) -> str: ... def toordinal(self) -> int: ... @@ -121,10 +123,9 @@ class Timestamp(datetime): tzinfo: _tzinfo | None = ..., fold: int = ..., ) -> datetime: ... - def astimezone(self: _S, tz: _tzinfo | None = ...) -> _S: ... + def astimezone(self: _DatetimeT, tz: _tzinfo | None = ...) -> _DatetimeT: ... def ctime(self) -> str: ... - # error: Signature of "isoformat" incompatible with supertype "datetime" - def isoformat(self, sep: str = ...) -> str: ... # type: ignore[override] + def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod def strptime(cls, date_string: str, format: str) -> datetime: ... def utcoffset(self) -> timedelta | None: ... @@ -139,8 +140,8 @@ class Timestamp(datetime): def __add__(self, other: np.ndarray) -> np.ndarray: ... @overload # TODO: other can also be Tick (but it cannot be resolved) - def __add__(self: _S, other: timedelta | np.timedelta64) -> _S: ... - def __radd__(self: _S, other: timedelta) -> _S: ... + def __add__(self: _DatetimeT, other: timedelta | np.timedelta64) -> _DatetimeT: ... + def __radd__(self: _DatetimeT, other: timedelta) -> _DatetimeT: ... @overload # type: ignore def __sub__(self, other: datetime) -> timedelta: ... @overload @@ -170,22 +171,25 @@ class Timestamp(datetime): def to_julian_date(self) -> np.float64: ... @property def asm8(self) -> np.datetime64: ... - def tz_convert(self: _S, tz: _tzinfo | str | None) -> _S: ... + def tz_convert(self: _DatetimeT, tz: _tzinfo | str | None) -> _DatetimeT: ... # TODO: could return NaT? def tz_localize( - self: _S, tz: _tzinfo | str | None, ambiguous: str = ..., nonexistent: str = ... - ) -> _S: ... - def normalize(self: _S) -> _S: ... + self: _DatetimeT, + tz: _tzinfo | str | None, + ambiguous: str = ..., + nonexistent: str = ..., + ) -> _DatetimeT: ... + def normalize(self: _DatetimeT) -> _DatetimeT: ... # TODO: round/floor/ceil could return NaT? def round( - self: _S, freq: str, ambiguous: bool | str = ..., nonexistent: str = ... - ) -> _S: ... + self: _DatetimeT, freq: str, ambiguous: bool | str = ..., nonexistent: str = ... + ) -> _DatetimeT: ... def floor( - self: _S, freq: str, ambiguous: bool | str = ..., nonexistent: str = ... - ) -> _S: ... + self: _DatetimeT, freq: str, ambiguous: bool | str = ..., nonexistent: str = ... + ) -> _DatetimeT: ... def ceil( - self: _S, freq: str, ambiguous: bool | str = ..., nonexistent: str = ... - ) -> _S: ... + self: _DatetimeT, freq: str, ambiguous: bool | str = ..., nonexistent: str = ... + ) -> _DatetimeT: ... def day_name(self, locale: str | None = ...) -> str: ... def month_name(self, locale: str | None = ...) -> str: ... @property