Use _typeshed.Self in Python 2, too (#6932)

This commit is contained in:
Alex Waygood
2022-01-16 22:44:51 +00:00
committed by GitHub
parent 0949e9e90d
commit 6a88d5e7ae
29 changed files with 156 additions and 160 deletions

View File

@@ -1,8 +1,10 @@
from _typeshed import Self
from datetime import date, datetime, timedelta
from typing import SupportsFloat, TypeVar, overload
from ._common import weekday
# We need the extra "Self" TypeVar to avoid overlapping __add__/__radd__ complaints from mypy
_SelfT = TypeVar("_SelfT", bound=relativedelta)
_DateT = TypeVar("_DateT", date, datetime)
# Work around attribute and type having the same name.
@@ -61,37 +63,37 @@ class relativedelta(object):
def weeks(self) -> int: ...
@weeks.setter
def weeks(self, value: int) -> None: ...
def normalized(self: _SelfT) -> _SelfT: ...
def normalized(self: Self) -> Self: ...
# TODO: use Union when mypy will handle it properly in overloaded operator
# methods (#2129, #1442, #1264 in mypy)
@overload
def __add__(self: _SelfT, other: relativedelta) -> _SelfT: ...
def __add__(self: _SelfT, other: relativedelta) -> _SelfT: ... # noqa: Y019
@overload
def __add__(self: _SelfT, other: timedelta) -> _SelfT: ...
def __add__(self: _SelfT, other: timedelta) -> _SelfT: ... # noqa: Y019
@overload
def __add__(self, other: _DateT) -> _DateT: ...
@overload
def __radd__(self: _SelfT, other: relativedelta) -> _SelfT: ...
def __radd__(self: _SelfT, other: relativedelta) -> _SelfT: ... # noqa: Y019
@overload
def __radd__(self: _SelfT, other: timedelta) -> _SelfT: ...
def __radd__(self: _SelfT, other: timedelta) -> _SelfT: ... # noqa: Y019
@overload
def __radd__(self, other: _DateT) -> _DateT: ...
@overload
def __rsub__(self: _SelfT, other: relativedelta) -> _SelfT: ...
def __rsub__(self: Self, other: relativedelta) -> Self: ...
@overload
def __rsub__(self: _SelfT, other: timedelta) -> _SelfT: ...
def __rsub__(self: Self, other: timedelta) -> Self: ...
@overload
def __rsub__(self, other: _DateT) -> _DateT: ...
def __sub__(self: _SelfT, other: relativedelta) -> _SelfT: ...
def __neg__(self: _SelfT) -> _SelfT: ...
def __sub__(self: Self, other: relativedelta) -> Self: ...
def __neg__(self: Self) -> Self: ...
def __bool__(self) -> bool: ...
def __nonzero__(self) -> bool: ...
def __mul__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __rmul__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __mul__(self: Self, other: SupportsFloat) -> Self: ...
def __rmul__(self: Self, other: SupportsFloat) -> Self: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __div__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __truediv__(self: _SelfT, other: SupportsFloat) -> _SelfT: ...
def __div__(self: Self, other: SupportsFloat) -> Self: ...
def __truediv__(self: Self, other: SupportsFloat) -> Self: ...
def __repr__(self) -> str: ...
def __abs__(self: _SelfT) -> _SelfT: ...
def __abs__(self: Self) -> Self: ...
def __hash__(self) -> int: ...