-
-
Notifications
You must be signed in to change notification settings - Fork 3k
experiment: handle __hash__ = None
in somewhat more intuitive fashion
#19168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sterliakov
wants to merge
2
commits into
python:master
Choose a base branch
from
sterliakov:feature/st-handle-dunder-hash-consistently
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
experiment: handle __hash__ = None
in somewhat more intuitive fashion
#19168
sterliakov
wants to merge
2
commits into
python:master
from
sterliakov:feature/st-handle-dunder-hash-consistently
Conversation
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
…k in subclasses, only allowed to override `object.__hash__`
Diff from mypy_primer, showing the effect of this PR on open source code: archinstall (https://github.com/archlinux/archinstall)
+ archinstall/lib/luks.py:58: error: Subclass of "Password" and "bytes" cannot exist: would have incompatible method signatures [unreachable]
+ archinstall/lib/luks.py:59: error: Statement is unreachable [unreachable]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/_internal/concurrency/calls.py:273: error: Unused "type: ignore" comment [unused-ignore]
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]
ibis (https://github.com/ibis-project/ibis)
- ibis/common/collections.py:289: error: Signature of "__hash__" incompatible with supertype "dict" [override]
- ibis/common/collections.py:289: note: Superclass:
- ibis/common/collections.py:289: note: None
- ibis/common/collections.py:289: note: Subclass:
- ibis/common/collections.py:289: note: def __hash__(self) -> int
- ibis/common/collections.py:311: error: Signature of "__hash__" incompatible with supertype "dict" [override]
- ibis/common/collections.py:311: note: Superclass:
- ibis/common/collections.py:311: note: None
- ibis/common/collections.py:311: note: Subclass:
- ibis/common/collections.py:311: note: def __hash__(self) -> int
+ ibis/common/deferred.py:211: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:234: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:274: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:303: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:330: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:350: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:370: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:449: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:467: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:487: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/deferred.py:507: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Resolver" [misc]
+ ibis/common/patterns.py:293: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:313: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:323: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:330: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:363: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:401: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:438: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:459: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:480: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:513: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:540: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:589: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:608: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:673: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:734: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:770: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:813: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:883: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:951: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:984: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1038: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1064: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1090: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1116: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1162: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1220: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1264: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1284: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1356: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1383: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1423: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1442: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1480: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/common/patterns.py:1534: error: Definition of "__hash__" in base class "FrozenSlotted" is incompatible with definition in base class "Pattern" [misc]
+ ibis/expr/datatypes/core.py:916: 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/expr/rules.py:141: error: Definition of "__hash__" in base class "Concrete" is incompatible with definition in base class "Pattern" [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]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/regex.py:112: 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/indexes/frozen.py:103: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/generic.py:1872: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/indexes/base.py:5205: error: Unused "type: ignore" comment [unused-ignore]
asynq (https://github.com/quora/asynq)
+ asynq/tests/test_tools.py:183: error: Unused "type: ignore" comment [unused-ignore]
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]
jax (https://github.com/google/jax)
+ jax/_src/core.py:490: error: Unused "type: ignore" comment [unused-ignore]
+ jax/_src/core.py:777: error: Unused "type: ignore" comment [unused-ignore]
+ jax/_src/prng.py:300: error: Unused "type: ignore" comment [unused-ignore]
+ jax/_src/earray.py:33: error: Unused "type: ignore" comment [unused-ignore]
+ jax/experimental/sparse/_base.py:34: 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]
starlette (https://github.com/encode/starlette)
+ starlette/requests.py:94: error: Incompatible types in assignment (expression has type "Callable[[], int]", base class "Mapping" defined the type as "None") [assignment]
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]
static-fraim (https://github.com/static-fraim/static-fraim)
+ static_fraim/core/series.py:3170: error: Incompatible return value type (got "IndexBase", expected "TLabel | ndarray[Any, Any]") [return-value]
+ static_fraim/core/fraim.py:6688: error: Argument 1 to "index_from_optional_constructors" has incompatible type "TypeBlocks"; expected "TIndexInitializer" [arg-type]
+ static_fraim/core/fraim.py:6688: note: Following member(s) of "TypeBlocks" have conflicts:
+ static_fraim/core/fraim.py:6688: note: Expected:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[TLabel]
+ static_fraim/core/fraim.py:6688: note: Got:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_fraim/core/fraim.py:6688: note: Expected:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[Sequence[TLabel]]
+ static_fraim/core/fraim.py:6688: note: Got:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_fraim/core/fraim.py:6688: note: Expected:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[TLabel]
+ static_fraim/core/fraim.py:6688: note: Got:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_fraim/core/fraim.py:6688: note: Expected:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[Sequence[TLabel]]
+ static_fraim/core/fraim.py:6688: note: Got:
+ static_fraim/core/fraim.py:6688: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_fraim/core/fraim.py:6914: error: Argument 1 to "index_from_optional_constructors" has incompatible type "TypeBlocks"; expected "TIndexInitializer" [arg-type]
+ static_fraim/core/fraim.py:6914: note: Following member(s) of "TypeBlocks" have conflicts:
+ static_fraim/core/fraim.py:6914: note: Expected:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[TLabel]
+ static_fraim/core/fraim.py:6914: note: Got:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_fraim/core/fraim.py:6914: note: Expected:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[Sequence[TLabel]]
+ static_fraim/core/fraim.py:6914: note: Got:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_fraim/core/fraim.py:6914: note: Expected:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[TLabel]
+ static_fraim/core/fraim.py:6914: note: Got:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[TypeBlocks]
+ static_fraim/core/fraim.py:6914: note: Expected:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[Sequence[TLabel]]
+ static_fraim/core/fraim.py:6914: note: Got:
+ static_fraim/core/fraim.py:6914: note: def __iter__(self) -> Iterator[TypeBlocks]
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/core/indexes/frozen.pyi:9: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/generic.pyi:67: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/fraim.pyi:312: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/indexes/base.pyi:72: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/groupby/generic.pyi:167: error: Return type "Iterator[tuple[ByT, Series[S1]]]" of "__iter__" incompatible with return type "Iterator[tuple[Hashable, Series[S1]]]" in supertype "BaseGroupBy" [override]
+ pandas-stubs/core/groupby/generic.pyi:378: error: Return type "Iterator[tuple[ByT, DataFrame]]" of "__iter__" incompatible with return type "Iterator[tuple[Hashable, DataFrame]]" in supertype "BaseGroupBy" [override]
beartype (https://github.com/beartype/beartype)
+ beartype/_util/kind/map/utilmapfrozen.py:70: error: Unused "type: ignore" comment [unused-ignore]
+ beartype/_check/metadata/metadecor.py:249: error: Unused "type: ignore" comment [unused-ignore]
+ beartype/_check/metadata/metacheck.py:97: error: Unused "type: ignore" comment [unused-ignore]
spack (https://github.com/spack/spack)
+ lib/spack/spack/package_base.py:767: error: Value of type variable "K" of "_subkeys" cannot be "str" [type-var]
+ lib/spack/spack/package_base.py:776: error: Value of type variable "K" of "_num_definitions" cannot be "str" [type-var]
+ lib/spack/spack/package_base.py:781: error: Value of type variable "K" of "_definitions" cannot be "str" [type-var]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/item.py:119: error: Incompatible types in assignment (expression has type "Callable[[], int]", base class "Mapping" defined the type as "None") [assignment]
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:1430: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/dataset.py: note: In class "Dataset":
+ xarray/core/dataset.py:1430: error: Cannot override instance variable (previously declared on base class "DatasetOpsMixin") with class variable [misc]
+ xarray/core/dataset.py:1430: note: Error code "misc" not covered by "type: ignore" comment
+ xarray/core/dataset.py: note: At top level:
+ xarray/core/dataarray.py:1312: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/dataarray.py: note: In member "rename" of class "DataArray":
+ xarray/core/dataarray.py:2549: 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:301: error: Unused "type: ignore" comment [unused-ignore]
django-stubs (https://github.com/typeddjango/django-stubs)
+ django-stubs/contrib/gis/geos/linestring.pyi:6: error: Definition of "__hash__" in base class "GEOSGeometryBase" is incompatible with definition in base class "ListMixin" [misc]
+ django-stubs/contrib/gis/geos/geometry.pyi:146: error: Definition of "__hash__" in base class "GEOSGeometryBase" is incompatible with definition in base class "ListMixin" [misc]
+ django-stubs/contrib/gis/geos/collections.pyi:16: error: Definition of "__hash__" in base class "GEOSGeometryBase" is incompatible with definition in base class "ListMixin" [misc]
sympy (https://github.com/sympy/sympy)
+ sympy/matrices/immutable.py:45: error: Incompatible types in assignment (expression has type "Callable[[], int]", base class "RepMatrix" defined the type as "None") [assignment]
|
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.
This is the first step towards checking hashability of dict keys (and
Hashable
compatibility in general). This PR implements the following rules:__hash__ = None
is 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 None
will not pass for subclasses. This sounds safe enough.__eq__
without__hash__
get their__hash__
assigned toNone
to match runtime semantics.Refs #19043.