Handle __hash__ = None in somewhat more intuitive fashion#19168
Open
sterliakov wants to merge 16 commits intopython:masterfrom
Open
Handle __hash__ = None in somewhat more intuitive fashion#19168sterliakov wants to merge 16 commits intopython:masterfrom
__hash__ = None in somewhat more intuitive fashion#19168sterliakov wants to merge 16 commits intopython:masterfrom
Conversation
…k in subclasses, only allowed to override `object.__hash__`
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
__hash__ = None in somewhat more intuitive fashion__hash__ = None in somewhat more intuitive fashion
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…-dunder-hash-consistently
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: beartype (https://github.com/beartype/beartype)
+ beartype/_check/metadata/metadecor.py:289: error: Unused "type: ignore" comment [unused-ignore]
+ beartype/_check/metadata/metacheck.py:97: error: Unused "type: ignore" comment [unused-ignore]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/regex.py:112: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/_internal/concurrency/calls.py:273: error: Unused "type: ignore" comment [unused-ignore]
colour (https://github.com/colour-science/colour)
- colour/utilities/structures.py:515: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- colour/io/luts/sequence.py:266: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- colour/io/luts/operator.py:411: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- colour/io/luts/lut.py:354: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
asynq (https://github.com/quora/asynq)
+ asynq/tests/test_tools.py:183: error: Unused "type: ignore" comment [unused-ignore]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/python_api.py:88: error: Unused "type: ignore" comment [unused-ignore]
+ src/_pytest/_code/source.py:50: error: Unused "type: ignore" comment [unused-ignore]
+ src/_pytest/_code/code.py:77: error: Unused "type: ignore" comment [unused-ignore]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/base.py:2207: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/generic.py:1868: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/indexes/base.py:5204: error: Unused "type: ignore" comment [unused-ignore]
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/datastructures/structures.py:648: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/datastructures/headers.py:108: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/routing/rules.py:912: error: Unused "type: ignore" comment [unused-ignore]
jax (https://github.com/google/jax)
+ jax/_src/core.py:535: error: Unused "type: ignore" comment [unused-ignore]
+ jax/_src/core.py:875: error: Unused "type: ignore" comment [unused-ignore]
+ jax/_src/earray.py:33: error: Unused "type: ignore" comment [unused-ignore]
+ jax/_src/prng.py:301: error: Unused "type: ignore" comment [unused-ignore]
+ jax/experimental/sparse/_base.py:34: error: Unused "type: ignore" comment [unused-ignore]
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/core/generic.pyi:67: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/frame.pyi:375: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/indexes/base.pyi:75: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/groupby/generic.pyi:209: error: Return type "Iterator[tuple[ByT, Series[S2]]]" of "__iter__" incompatible with return type "Iterator[tuple[Hashable, Series[S2]]]" in supertype "pandas.core.groupby.groupby.BaseGroupBy" [override]
+ pandas-stubs/core/groupby/generic.pyi:449: error: Return type "Iterator[tuple[ByT, DataFrame]]" of "__iter__" incompatible with return type "Iterator[tuple[Hashable, DataFrame]]" in supertype "pandas.core.groupby.groupby.BaseGroupBy" [override]
ibis (https://github.com/ibis-project/ibis)
- ibis/common/bases.py:167: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- ibis/common/bases.py:205: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- ibis/common/bases.py:249: error: Signature of "__hash__" incompatible with supertype "Slotted" [override]
- ibis/common/bases.py:249: note: Superclass:
- ibis/common/bases.py:249: note: None
- ibis/common/bases.py:249: note: Subclass:
- ibis/common/bases.py:249: note: def __hash__(self) -> int
- ibis/common/collections.py:153: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- ibis/common/collections.py:291: error: Signature of "__hash__" incompatible with supertype "Mapping" [override]
- ibis/common/collections.py:291: note: Superclass:
- ibis/common/collections.py:291: note: None
- ibis/common/collections.py:291: note: Subclass:
- ibis/common/collections.py:291: note: def __hash__(self) -> int
- ibis/common/collections.py:313: note: Superclass:
- ibis/common/collections.py:313: note: None
- ibis/common/collections.py:313: note: Subclass:
- ibis/common/collections.py:313: note: def __hash__(self) -> int
- ibis/common/collections.py:313: error: Signature of "__hash__" incompatible with supertype "Mapping" [override]
- ibis/common/deferred.py:180: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- ibis/common/patterns.py:660: error: Signature of "__hash__" incompatible with supertype "Slotted" [override]
- ibis/common/patterns.py:660: note: Superclass:
- ibis/common/patterns.py:660: note: None
- ibis/common/patterns.py:660: note: Subclass:
- ibis/common/patterns.py:660: note: def __hash__(self) -> int
- ibis/common/patterns.py:937: error: Signature of "__hash__" incompatible with supertype "Slotted" [override]
- ibis/common/patterns.py:937: note: Superclass:
- ibis/common/patterns.py:937: note: None
- ibis/common/patterns.py:937: note: Subclass:
- ibis/common/patterns.py:937: note: def __hash__(self) -> int
- ibis/common/grounds.py:164: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- ibis/common/grounds.py:220: error: Signature of "__hash__" incompatible with supertype "Comparable" [override]
- ibis/common/grounds.py:220: note: Superclass:
- ibis/common/grounds.py:220: note: None
- ibis/common/grounds.py:220: note: Subclass:
- ibis/common/grounds.py:220: note: def __hash__(self) -> int
- ibis/common/grounds.py:220: error: Signature of "__hash__" incompatible with supertype "Annotable" [override]
- ibis/common/grounds.py:220: note: Superclass:
- ibis/common/grounds.py:220: note: None
- ibis/common/grounds.py:220: note: Subclass:
- ibis/common/grounds.py:220: note: def __hash__(self) -> int
- ibis/common/egraph.py:124: error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[], int]") [assignment]
- ibis/expr/datatypes/core.py:941: error: Definition of "__hash__" in base class "Concrete" is incompatible with definition in base class "Mapping" [misc]
- ibis/expr/schema.py:25: error: Definition of "__hash__" in base class "Concrete" is incompatible with definition in base class "Mapping" [misc]
- ibis/common/tests/test_grounds.py:142: error: Definition of "__hash__" in base class "Concrete" is incompatible with definition in base class "Mapping" [misc]
mkdocs (https://github.com/mkdocs/mkdocs)
+ mkdocs/utils/templates.py:47: error: Subclass of "ExtraScriptValue" and "str" cannot exist: would have incompatible method signatures [unreachable]
schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/jsonld_context.py: note: In function "pred":
+ schema_salad/jsonld_context.py:53:31: error: Subclass of "str" and "MutableMapping[Any, Any]" cannot exist: would have incompatible method signatures [unreachable]
+ schema_salad/jsonld_context.py:54:21: error: Statement is unreachable [unreachable]
+ schema_salad/schema.py: note: In function "get_anon_name":
+ schema_salad/schema.py:422:27: error: Subclass of "str" and "Mapping[Any, Any]" cannot exist: would have incompatible method signatures [unreachable]
+ schema_salad/schema.py:423:17: error: Statement is unreachable [unreachable]
static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/series.py:3346: error: Incompatible return value type (got "IndexBase", expected "TLabel | ndarray[Any, Any]") [return-value]
+ static_frame/core/frame.py:7056: error: Argument 1 to "index_from_optional_constructors" has incompatible type "TypeBlocks"; expected "TIndexInitializer" [arg-type]
+ static_frame/core/frame.py:7056: note: Following member(s) of "TypeBlocks" have conflicts:
+ static_frame/core/frame.py:7056: note: Expected:
+ static_frame/core/frame.py:7056: note: def __iter__(self) -> Iterator[TLabel]
+ static_frame/core/frame.py:7056: note: Got:
+ static_frame/core/frame.py:7056: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_frame/core/frame.py:7056: note: Following member(s) of "TypeBlocks" have conflicts:
+ static_frame/core/frame.py:7056: note: Expected:
+ static_frame/core/frame.py:7056: note: def __iter__(self) -> Iterator[Sequence[TLabel]]
+ static_frame/core/frame.py:7056: note: Got:
+ static_frame/core/frame.py:7056: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_frame/core/frame.py:7298: error: Argument 1 to "index_from_optional_constructors" has incompatible type "TypeBlocks"; expected "TIndexInitializer" [arg-type]
+ static_frame/core/frame.py:7298: note: Following member(s) of "TypeBlocks" have conflicts:
+ static_frame/core/frame.py:7298: note: Expected:
+ static_frame/core/frame.py:7298: note: def __iter__(self) -> Iterator[TLabel]
+ static_frame/core/frame.py:7298: note: Got:
+ static_frame/core/frame.py:7298: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_frame/core/frame.py:7298: note: Following member(s) of "TypeBlocks" have conflicts:
+ static_frame/core/frame.py:7298: note: Expected:
+ static_frame/core/frame.py:7298: note: def __iter__(self) -> Iterator[Sequence[TLabel]]
+ static_frame/core/frame.py:7298: note: Got:
+ static_frame/core/frame.py:7298: note: def __iter__(self) -> Iterator[TypeBlocks]
xarray (https://github.com/pydata/xarray)
+ xarray/core/_typed_ops.py:93: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:362: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:736: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1164: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1376: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1502: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/dataset.py:1510: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/dataset.py: note: In class "Dataset":
+ xarray/core/dataset.py:1510: error: Cannot override instance variable (previously declared on base class "DatasetOpsMixin") with class variable [misc]
+ xarray/core/dataset.py:1510: note: Error code "misc" not covered by "type: ignore" comment
+ xarray/core/dataset.py: note: At top level:
+ xarray/core/dataarray.py:1364: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/dataarray.py: note: In member "rename" of class "DataArray":
+ xarray/core/dataarray.py:2601: error: Argument "name" to "_replace" of "DataArray" has incompatible type "Hashable | Mapping[Any, Hashable]"; expected "Hashable | Default | None" [arg-type]
+ xarray/core/dataarray.py: note: At top level:
+ xarray/core/datatree.py:303: error: Unused "type: ignore" comment [unused-ignore]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4266. Fixes #18622. Refs #2455.
This is the first step towards checking hashability of dict keys (and
Hashablecompatibility in general). This PR implements the following rules:__hash__ = Noneis only allowed on classes who inherited__hash__directly fromobject(no redefinitions in MRO)def __hash__is allowed on subclasses whose parents declare__hash__ = None- it is a relatively common solution to derive a hashable subclass, and LSP violation only meansassert SomeCls.__hash__ is Nonewill not pass for subclasses. This sounds safe enough.__eq__without__hash__get their__hash__assigned toNoneto match runtime semantics. Protocols are exempt from this as defining__eq__on protocol just requires classes that support__eq__, not necessarily unhashable ones.Refs #19043.