mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-23 19:41:51 +08:00
Always use _typeshed.Self, where applicable (#6880)
* Always use `_typeshed.Self`, where applicable * Revert changes to `google-cloud-ndb` (ambiguous) * Remove empty line added by script * Revert changes to `stubs/python-dateutil/dateutil/relativedelta.pyi` * Manually add a few more that the script missed * Improve `filelock` annotation Source code here:79ec7b2826/src/filelock/_api.py (L207)* Improve `opentracing/scope` annotation Source code here:3e1d357a34/opentracing/scope.py (L71)* Improve `redis/client` stub Source code here:15f315a496/redis/client.py (L1217)* Improve `redis/lock` annotation Source code here:15f315a496/redis/lock.py (L155)* Improve `requests/models` annotation Source code here:d718e75383/requests/models.py (L653)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from time import struct_time
|
||||
from typing import ClassVar, NamedTuple, NoReturn, SupportsAbs, TypeVar, overload
|
||||
from typing_extensions import final
|
||||
|
||||
_S = TypeVar("_S")
|
||||
_D = TypeVar("_D", bound=date)
|
||||
|
||||
MINYEAR: int
|
||||
@@ -36,19 +36,19 @@ class date:
|
||||
min: ClassVar[date]
|
||||
max: ClassVar[date]
|
||||
resolution: ClassVar[timedelta]
|
||||
def __new__(cls: type[_S], year: int, month: int, day: int) -> _S: ...
|
||||
def __new__(cls: type[Self], year: int, month: int, day: int) -> Self: ...
|
||||
@classmethod
|
||||
def fromtimestamp(cls: type[_S], __timestamp: float) -> _S: ...
|
||||
def fromtimestamp(cls: type[Self], __timestamp: float) -> Self: ...
|
||||
@classmethod
|
||||
def today(cls: type[_S]) -> _S: ...
|
||||
def today(cls: type[Self]) -> Self: ...
|
||||
@classmethod
|
||||
def fromordinal(cls: type[_S], __n: int) -> _S: ...
|
||||
def fromordinal(cls: type[Self], __n: int) -> Self: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls: type[_S], __date_string: str) -> _S: ...
|
||||
def fromisoformat(cls: type[Self], __date_string: str) -> Self: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
@classmethod
|
||||
def fromisocalendar(cls: type[_S], year: int, week: int, day: int) -> _S: ...
|
||||
def fromisocalendar(cls: type[Self], year: int, week: int, day: int) -> Self: ...
|
||||
@property
|
||||
def year(self) -> int: ...
|
||||
@property
|
||||
@@ -67,10 +67,10 @@ class date:
|
||||
def __ge__(self, __other: date) -> bool: ...
|
||||
def __gt__(self, __other: date) -> bool: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def __add__(self: _S, __other: timedelta) -> _S: ...
|
||||
def __radd__(self: _S, __other: timedelta) -> _S: ...
|
||||
def __add__(self: Self, __other: timedelta) -> Self: ...
|
||||
def __radd__(self: Self, __other: timedelta) -> Self: ...
|
||||
@overload
|
||||
def __sub__(self: _D, __other: timedelta) -> _D: ...
|
||||
def __sub__(self: Self, __other: timedelta) -> Self: ...
|
||||
@overload
|
||||
def __sub__(self, __other: datetime) -> NoReturn: ...
|
||||
@overload
|
||||
@@ -98,7 +98,7 @@ class time:
|
||||
max: ClassVar[time]
|
||||
resolution: ClassVar[timedelta]
|
||||
def __new__(
|
||||
cls: type[_S],
|
||||
cls: type[Self],
|
||||
hour: int = ...,
|
||||
minute: int = ...,
|
||||
second: int = ...,
|
||||
@@ -106,7 +106,7 @@ class time:
|
||||
tzinfo: _tzinfo | None = ...,
|
||||
*,
|
||||
fold: int = ...,
|
||||
) -> _S: ...
|
||||
) -> Self: ...
|
||||
@property
|
||||
def hour(self) -> int: ...
|
||||
@property
|
||||
@@ -127,7 +127,7 @@ class time:
|
||||
def isoformat(self, timespec: str = ...) -> str: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls: type[_S], __time_string: str) -> _S: ...
|
||||
def fromisoformat(cls: type[Self], __time_string: str) -> Self: ...
|
||||
def strftime(self, __format: str) -> str: ...
|
||||
def __format__(self, __fmt: str) -> str: ...
|
||||
def utcoffset(self) -> timedelta | None: ...
|
||||
@@ -152,7 +152,7 @@ class timedelta(SupportsAbs[timedelta]):
|
||||
max: ClassVar[timedelta]
|
||||
resolution: ClassVar[timedelta]
|
||||
def __new__(
|
||||
cls: type[_S],
|
||||
cls: type[Self],
|
||||
days: float = ...,
|
||||
seconds: float = ...,
|
||||
microseconds: float = ...,
|
||||
@@ -160,7 +160,7 @@ class timedelta(SupportsAbs[timedelta]):
|
||||
minutes: float = ...,
|
||||
hours: float = ...,
|
||||
weeks: float = ...,
|
||||
) -> _S: ...
|
||||
) -> Self: ...
|
||||
@property
|
||||
def days(self) -> int: ...
|
||||
@property
|
||||
@@ -199,7 +199,7 @@ class datetime(date):
|
||||
max: ClassVar[datetime]
|
||||
resolution: ClassVar[timedelta]
|
||||
def __new__(
|
||||
cls: type[_S],
|
||||
cls: type[Self],
|
||||
year: int,
|
||||
month: int,
|
||||
day: int,
|
||||
@@ -210,7 +210,7 @@ class datetime(date):
|
||||
tzinfo: _tzinfo | None = ...,
|
||||
*,
|
||||
fold: int = ...,
|
||||
) -> _S: ...
|
||||
) -> Self: ...
|
||||
@property
|
||||
def hour(self) -> int: ...
|
||||
@property
|
||||
@@ -227,26 +227,26 @@ class datetime(date):
|
||||
# but it is named "timestamp" in the C implementation and "t" in the Python implementation,
|
||||
# so it is only truly *safe* to pass it as a positional argument.
|
||||
@classmethod
|
||||
def fromtimestamp(cls: type[_S], __timestamp: float, tz: _tzinfo | None = ...) -> _S: ...
|
||||
def fromtimestamp(cls: type[Self], __timestamp: float, tz: _tzinfo | None = ...) -> Self: ...
|
||||
@classmethod
|
||||
def utcfromtimestamp(cls: type[_S], __t: float) -> _S: ...
|
||||
def utcfromtimestamp(cls: type[Self], __t: float) -> Self: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
@classmethod
|
||||
def now(cls: type[_S], tz: _tzinfo | None = ...) -> _S: ...
|
||||
def now(cls: type[Self], tz: _tzinfo | None = ...) -> Self: ...
|
||||
else:
|
||||
@overload
|
||||
@classmethod
|
||||
def now(cls: type[_S], tz: None = ...) -> _S: ...
|
||||
def now(cls: type[Self], tz: None = ...) -> Self: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def now(cls, tz: _tzinfo) -> datetime: ...
|
||||
@classmethod
|
||||
def utcnow(cls: type[_S]) -> _S: ...
|
||||
def utcnow(cls: type[Self]) -> Self: ...
|
||||
@classmethod
|
||||
def combine(cls, date: _date, time: _time, tzinfo: _tzinfo | None = ...) -> datetime: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls: type[_S], __date_string: str) -> _S: ...
|
||||
def fromisoformat(cls: type[Self], __date_string: str) -> Self: ...
|
||||
def timestamp(self) -> float: ...
|
||||
def utctimetuple(self) -> struct_time: ...
|
||||
def date(self) -> _date: ...
|
||||
@@ -266,7 +266,7 @@ class datetime(date):
|
||||
fold: int = ...,
|
||||
) -> datetime: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def astimezone(self: _S, tz: _tzinfo | None = ...) -> _S: ...
|
||||
def astimezone(self: Self, tz: _tzinfo | None = ...) -> Self: ...
|
||||
else:
|
||||
def astimezone(self, tz: _tzinfo | None = ...) -> datetime: ...
|
||||
def ctime(self) -> str: ...
|
||||
@@ -282,7 +282,7 @@ class datetime(date):
|
||||
def __gt__(self, __other: datetime) -> bool: ... # type: ignore[override]
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload # type: ignore[override]
|
||||
def __sub__(self: _D, __other: timedelta) -> _D: ...
|
||||
def __sub__(self: Self, __other: timedelta) -> Self: ...
|
||||
@overload
|
||||
def __sub__(self: _D, __other: _D) -> timedelta: ...
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user