Skip to content

Commit

Permalink
Revert "Remove un-needed __hash__ methods from stdlib (#8465)" (#…
Browse files Browse the repository at this point in the history
…10426)

Reverts #8465
Fixes #10424
Closes #10425

#8465 caused regressions: see #10424 and python/mypy#13800. Since it didn't fix any known problems (just some stylistic nits that we had), let's just revert the PR.
  • Loading branch information
AlexWaygood authored Jul 9, 2023
1 parent aed8c3f commit 81b8211
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/_decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Decimal:
def from_float(cls, __f: float) -> Self: ...
def __bool__(self) -> bool: ...
def compare(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
def __hash__(self) -> int: ...
def as_tuple(self) -> DecimalTuple: ...
def as_integer_ratio(self) -> tuple[int, int]: ...
def to_eng_string(self, context: Context | None = None) -> str: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/_weakref.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ReferenceType(Generic[_T]):
__callback__: Callable[[ReferenceType[_T]], Any]
def __new__(cls, __o: _T, __callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
def __call__(self) -> _T | None: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

Expand Down
1 change: 1 addition & 0 deletions stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class TimerHandle(Handle):
loop: AbstractEventLoop,
context: Context | None = None,
) -> None: ...
def __hash__(self) -> int: ...
def when(self) -> float: ...
def __lt__(self, other: TimerHandle) -> bool: ...
def __le__(self, other: TimerHandle) -> bool: ...
Expand Down
5 changes: 5 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class int:
def __float__(self) -> float: ...
def __int__(self) -> int: ...
def __abs__(self) -> int: ...
def __hash__(self) -> int: ...
def __bool__(self) -> bool: ...
def __index__(self) -> int: ...

Expand Down Expand Up @@ -379,6 +380,7 @@ class float:
def __int__(self) -> int: ...
def __float__(self) -> float: ...
def __abs__(self) -> float: ...
def __hash__(self) -> int: ...
def __bool__(self) -> bool: ...

class complex:
Expand Down Expand Up @@ -418,6 +420,7 @@ class complex:
def __neg__(self) -> complex: ...
def __pos__(self) -> complex: ...
def __abs__(self) -> float: ...
def __hash__(self) -> int: ...
def __bool__(self) -> bool: ...
if sys.version_info >= (3, 11):
def __complex__(self) -> complex: ...
Expand Down Expand Up @@ -585,6 +588,7 @@ class str(Sequence[str]):
def __ge__(self, __value: str) -> bool: ...
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
def __gt__(self, __value: str) -> bool: ...
def __hash__(self) -> int: ...
@overload
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
@overload
Expand Down Expand Up @@ -690,6 +694,7 @@ class bytes(Sequence[int]):
def maketrans(__frm: ReadableBuffer, __to: ReadableBuffer) -> bytes: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[int]: ...
def __hash__(self) -> int: ...
@overload
def __getitem__(self, __key: SupportsIndex) -> int: ...
@overload
Expand Down
4 changes: 4 additions & 0 deletions stdlib/datetime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class timezone(tzinfo):
def tzname(self, __dt: datetime | None) -> str: ...
def utcoffset(self, __dt: datetime | None) -> timedelta: ...
def dst(self, __dt: datetime | None) -> None: ...
def __hash__(self) -> int: ...

if sys.version_info >= (3, 11):
UTC: timezone
Expand Down Expand Up @@ -106,6 +107,7 @@ class date:
@overload
def __sub__(self, __value: date) -> timedelta: ...

def __hash__(self) -> int: ...
def weekday(self) -> int: ...
def isoweekday(self) -> int: ...
if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -143,6 +145,7 @@ class time:
def __lt__(self, __value: time) -> bool: ...
def __ge__(self, __value: time) -> bool: ...
def __gt__(self, __value: time) -> bool: ...
def __hash__(self) -> int: ...
def isoformat(self, timespec: str = ...) -> str: ...
@classmethod
def fromisoformat(cls, __time_string: str) -> Self: ...
Expand Down Expand Up @@ -217,6 +220,7 @@ class timedelta:
def __ge__(self, __value: timedelta) -> bool: ...
def __gt__(self, __value: timedelta) -> bool: ...
def __bool__(self) -> bool: ...
def __hash__(self) -> int: ...

class datetime(date):
min: ClassVar[datetime]
Expand Down
3 changes: 3 additions & 0 deletions stdlib/doctest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Example:
indent: int = 0,
options: dict[int, bool] | None = None,
) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...

class DocTest:
Expand All @@ -103,6 +104,7 @@ class DocTest:
lineno: int | None,
docstring: str | None,
) -> None: ...
def __hash__(self) -> int: ...
def __lt__(self, other: DocTest) -> bool: ...
def __eq__(self, other: object) -> bool: ...

Expand Down Expand Up @@ -210,6 +212,7 @@ class DocTestCase(unittest.TestCase):
) -> None: ...
def runTest(self) -> None: ...
def format_failure(self, err: str) -> str: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...

class SkipDocTestCase(DocTestCase):
Expand Down
1 change: 1 addition & 0 deletions stdlib/ipaddress.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class _IPAddressBase:
class _BaseAddress(_IPAddressBase, SupportsInt):
def __init__(self, address: object) -> None: ...
def __add__(self, other: int) -> Self: ...
def __hash__(self) -> int: ...
def __int__(self) -> int: ...
def __sub__(self, other: int) -> Self: ...
if sys.version_info >= (3, 9):
Expand Down
1 change: 1 addition & 0 deletions stdlib/pathlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PurePath(PathLike[str]):
@property
def stem(self) -> str: ...
def __new__(cls, *args: StrPath) -> Self: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __fspath__(self) -> str: ...
def __lt__(self, other: PurePath) -> bool: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/plistlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if sys.version_info >= (3, 8):
def __init__(self, data: int) -> None: ...
def __index__(self) -> int: ...
def __reduce__(self) -> tuple[type[Self], tuple[int]]: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...

class InvalidFileException(ValueError):
Expand Down
1 change: 1 addition & 0 deletions stdlib/sqlite3/dbapi2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class Row:
def __getitem__(self, __key: int | str) -> Any: ...
@overload
def __getitem__(self, __key: slice) -> tuple[Any, ...]: ...
def __hash__(self) -> int: ...
def __iter__(self) -> Iterator[Any]: ...
def __len__(self) -> int: ...
# These return NotImplemented for anything that is not a Row.
Expand Down
1 change: 1 addition & 0 deletions stdlib/statistics.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ if sys.version_info >= (3, 8):
__radd__ = __add__
def __rsub__(self, x2: float | NormalDist) -> NormalDist: ...
__rmul__ = __mul__
def __hash__(self) -> int: ...

if sys.version_info >= (3, 12):
def correlation(
Expand Down
1 change: 1 addition & 0 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ class ForwardRef:
def _evaluate(self, globalns: dict[str, Any] | None, localns: dict[str, Any] | None) -> Any | None: ...

def __eq__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 11):
def __or__(self, other: Any) -> _SpecialForm: ...
def __ror__(self, other: Any) -> _SpecialForm: ...
Expand Down

0 comments on commit 81b8211

Please sign in to comment.