From 89f4dee4522beaa967b47136c3f3d54f33ff0e1f Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 22 Jun 2022 11:58:00 +0100 Subject: [PATCH] Improve several `__hash__` methods (#8128) --- stdlib/_decimal.pyi | 5 +++-- stubs/SQLAlchemy/sqlalchemy/engine/row.pyi | 2 +- .../sqlalchemy/orm/descriptor_props.pyi | 4 ++-- .../sqlalchemy/orm/relationships.pyi | 4 ++-- stubs/SQLAlchemy/sqlalchemy/sql/base.pyi | 4 ++-- .../sqlalchemy/testing/pickleable.pyi | 4 ++-- stubs/invoke/invoke/config.pyi | 4 ++-- stubs/python-dateutil/dateutil/tz/_common.pyi | 6 +++--- stubs/python-dateutil/dateutil/tz/tz.pyi | 18 +++++++++--------- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/stdlib/_decimal.pyi b/stdlib/_decimal.pyi index a259058ee..515ed13d2 100644 --- a/stdlib/_decimal.pyi +++ b/stdlib/_decimal.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import Self from collections.abc import Container, Sequence from types import TracebackType -from typing import Any, NamedTuple, Union, overload +from typing import Any, ClassVar, NamedTuple, Union, overload from typing_extensions import TypeAlias _Decimal: TypeAlias = Decimal | int @@ -209,7 +209,8 @@ class Context: def clear_traps(self) -> None: ... def copy(self) -> Context: ... def __copy__(self) -> Context: ... - __hash__: Any + # see https://github.com/python/cpython/issues/94107 + __hash__: ClassVar[None] # type: ignore[assignment] def Etiny(self) -> int: ... def Etop(self) -> int: ... def create_decimal(self, __num: _DecimalNew = ...) -> Decimal: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/engine/row.pyi b/stubs/SQLAlchemy/sqlalchemy/engine/row.pyi index 743be40f2..2c588e9b9 100644 --- a/stubs/SQLAlchemy/sqlalchemy/engine/row.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/engine/row.pyi @@ -19,7 +19,7 @@ class Row(BaseRow, Sequence[Any], metaclass=abc.ABCMeta): @property def index(self): ... def __contains__(self, key): ... - __hash__: Any + __hash__ = BaseRow.__hash__ def __lt__(self, other): ... def __le__(self, other): ... def __ge__(self, other): ... diff --git a/stubs/SQLAlchemy/sqlalchemy/orm/descriptor_props.pyi b/stubs/SQLAlchemy/sqlalchemy/orm/descriptor_props.pyi index c4574b10b..3021db358 100644 --- a/stubs/SQLAlchemy/sqlalchemy/orm/descriptor_props.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/orm/descriptor_props.pyi @@ -1,4 +1,4 @@ -from typing import Any, Generic, TypeVar +from typing import Any, ClassVar, Generic, TypeVar from ..sql.operators import ColumnOperators from ..util import memoized_property @@ -37,7 +37,7 @@ class CompositeProperty(DescriptorProperty): def create_row_processor(self, query, procs, labels): ... class Comparator(PropComparator[_T], Generic[_T]): - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] @memoized_property def clauses(self): ... def __clause_element__(self): ... diff --git a/stubs/SQLAlchemy/sqlalchemy/orm/relationships.pyi b/stubs/SQLAlchemy/sqlalchemy/orm/relationships.pyi index 91dee9c8f..09f4eefdf 100644 --- a/stubs/SQLAlchemy/sqlalchemy/orm/relationships.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/orm/relationships.pyi @@ -1,4 +1,4 @@ -from typing import Any, Generic, TypeVar +from typing import Any, ClassVar, Generic, TypeVar from ..sql.operators import ColumnOperators from ..util import memoized_property @@ -101,7 +101,7 @@ class RelationshipProperty(StrategizedProperty): def of_type(self, cls): ... def and_(self, *other): ... def in_(self, other) -> ColumnOperators[_T]: ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __eq__(self, other): ... def any(self, criterion: Any | None = ..., **kwargs): ... def has(self, criterion: Any | None = ..., **kwargs): ... diff --git a/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi b/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi index fb006721d..fd7d08865 100644 --- a/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/sql/base.pyi @@ -1,6 +1,6 @@ from _typeshed import Self from collections.abc import MutableMapping -from typing import Any +from typing import Any, ClassVar from .. import util from ..util import HasMemoized, hybridmethod, memoized_property @@ -133,7 +133,7 @@ class ColumnCollection: def clear(self) -> None: ... def remove(self, column) -> None: ... def update(self, iter_) -> None: ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def add(self, column, key: Any | None = ...) -> None: ... def contains_column(self, col): ... def as_immutable(self): ... diff --git a/stubs/SQLAlchemy/sqlalchemy/testing/pickleable.pyi b/stubs/SQLAlchemy/sqlalchemy/testing/pickleable.pyi index 837dfac04..59664bd63 100644 --- a/stubs/SQLAlchemy/sqlalchemy/testing/pickleable.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/testing/pickleable.pyi @@ -21,14 +21,14 @@ class Foo: stuff: Any moredata: Any def __init__(self, moredata, stuff: str = ...) -> None: ... - __hash__: Any + __hash__ = object.__hash__ def __eq__(self, other): ... class Bar: x: Any y: Any def __init__(self, x, y) -> None: ... - __hash__: Any + __hash__ = object.__hash__ def __eq__(self, other): ... class OldSchool: diff --git a/stubs/invoke/invoke/config.pyi b/stubs/invoke/invoke/config.pyi index c64180eb2..2659a6b2f 100644 --- a/stubs/invoke/invoke/config.pyi +++ b/stubs/invoke/invoke/config.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, ClassVar def load_source(name: str, path: str) -> dict[str, Any]: ... @@ -9,7 +9,7 @@ class DataProxy: def __setattr__(self, key, value) -> None: ... def __iter__(self): ... def __eq__(self, other): ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __len__(self): ... def __setitem__(self, key, value) -> None: ... def __getitem__(self, key): ... diff --git a/stubs/python-dateutil/dateutil/tz/_common.pyi b/stubs/python-dateutil/dateutil/tz/_common.pyi index 807789fef..38a98601f 100644 --- a/stubs/python-dateutil/dateutil/tz/_common.pyi +++ b/stubs/python-dateutil/dateutil/tz/_common.pyi @@ -1,5 +1,5 @@ from datetime import datetime, timedelta, tzinfo -from typing import Any +from typing import ClassVar def tzname_in_python2(namefunc): ... def enfold(dt: datetime, fold: int = ...): ... @@ -19,6 +19,6 @@ class tzrangebase(_tzinfo): def tzname(self, dt: datetime | None) -> str: ... def fromutc(self, dt: datetime) -> datetime: ... def is_ambiguous(self, dt: datetime) -> bool: ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __ne__(self, other): ... - __reduce__: Any + __reduce__ = object.__reduce__ diff --git a/stubs/python-dateutil/dateutil/tz/tz.pyi b/stubs/python-dateutil/dateutil/tz/tz.pyi index e67a0f46a..dfafcdda0 100644 --- a/stubs/python-dateutil/dateutil/tz/tz.pyi +++ b/stubs/python-dateutil/dateutil/tz/tz.pyi @@ -1,5 +1,5 @@ import datetime -from typing import Any, Protocol, TypeVar +from typing import Any, ClassVar, Protocol, TypeVar from typing_extensions import Literal from ..relativedelta import relativedelta @@ -18,9 +18,9 @@ class tzutc(datetime.tzinfo): def is_ambiguous(self, dt: datetime.datetime | None) -> bool: ... def fromutc(self, dt: _DT) -> _DT: ... def __eq__(self, other): ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __ne__(self, other): ... - __reduce__: Any + __reduce__ = object.__reduce__ class tzoffset(datetime.tzinfo): def __init__(self, name, offset) -> None: ... @@ -30,9 +30,9 @@ class tzoffset(datetime.tzinfo): def tzname(self, dt: datetime.datetime | None) -> str: ... def fromutc(self, dt: _DT) -> _DT: ... def __eq__(self, other): ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __ne__(self, other): ... - __reduce__: Any + __reduce__ = object.__reduce__ @classmethod def instance(cls, name, offset) -> tzoffset: ... @@ -43,14 +43,14 @@ class tzlocal(_tzinfo): def tzname(self, dt: datetime.datetime | None) -> str: ... def is_ambiguous(self, dt: datetime.datetime | None) -> bool: ... def __eq__(self, other): ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __ne__(self, other): ... - __reduce__: Any + __reduce__ = object.__reduce__ class _ttinfo: def __init__(self) -> None: ... def __eq__(self, other): ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __ne__(self, other): ... class _TZFileReader(Protocol): @@ -66,7 +66,7 @@ class tzfile(_tzinfo): def dst(self, dt: datetime.datetime | None) -> datetime.timedelta | None: ... def tzname(self, dt: datetime.datetime | None) -> str: ... def __eq__(self, other): ... - __hash__: Any + __hash__: ClassVar[None] # type: ignore[assignment] def __ne__(self, other): ... def __reduce__(self): ... def __reduce_ex__(self, protocol): ...