-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Experiment: loosen object.__eq__ and object.__ne__ signature.
#15344
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
randolf-scholz
wants to merge
3
commits into
python:main
Choose a base branch
from
randolf-scholz:object_eq_any
base: main
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.
+6
−2
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
This comment has been minimized.
This comment has been minimized.
…r than Any to avoid no-ant-return errors.
This comment has been minimized.
This comment has been minimized.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: kornia (https://github.com/kornia/kornia)
- kornia/core/tensor_wrapper.py:232: error: Return type "TensorWrapper" of "__eq__" incompatible with return type "bool" in supertype "builtins.object" [override]
- kornia/core/tensor_wrapper.py:236: error: Return type "TensorWrapper" of "__ne__" incompatible with return type "bool" in supertype "builtins.object" [override]
freqtrade (https://github.com/freqtrade/freqtrade)
+ freqtrade/plugins/pairlist/PercentChangePairList.py:236: error: Unused "type: ignore" comment [unused-ignore]
spark (https://github.com/apache/spark)
+ python/pyspark/sql/column.py:171: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/sql/column.py:179: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/sql/classic/column.py:264: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/sql/classic/column.py:270: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/pandas/frame.py:1154: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/pandas/frame.py:1157: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/pandas/base.py:423: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/pandas/base.py:432: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/sql/connect/column.py:284: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/sql/connect/column.py:386: error: Unused "type: ignore" comment [unused-ignore]
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/builders/html/_build_info.py:63: error: Unused "type: ignore" comment [unused-ignore]
xarray (https://github.com/pydata/xarray)
+ xarray/core/_typed_ops.py:85: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:88: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:342: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:351: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:710: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:722: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1132: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1147: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1368: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1371: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1494: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/core/_typed_ops.py:1497: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/tests/arrays.py:199: error: Unused "type: ignore" comment [unused-ignore]
core (https://github.com/home-assistant/core)
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/node_transpose.py:406: error: Unused "type: ignore" comment [unused-ignore]
+ static_frame/core/node_transpose.py:411: error: Unused "type: ignore" comment [unused-ignore]
+ static_frame/core/node_fill_value.py:645: error: Unused "type: ignore" comment [unused-ignore]
+ static_frame/core/node_fill_value.py:652: error: Unused "type: ignore" comment [unused-ignore]
ibis (https://github.com/ibis-project/ibis)
- ibis/common/deferred.py:46: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ibis/common/deferred.py:46: note: This violates the Liskov substitution principle
- ibis/common/deferred.py:46: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ibis/common/deferred.py:46: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ibis/common/deferred.py:46: note: def __eq__(self, other: object) -> bool:
- ibis/common/deferred.py:46: note: if not isinstance(other, Resolver):
- ibis/common/deferred.py:46: note: return NotImplemented
- ibis/common/deferred.py:46: note: return <logic to compare two Resolver instances>
+ ibis/common/deferred.py:183: error: Unused "type: ignore" comment [unused-ignore]
- ibis/common/patterns.py:225: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ibis/common/patterns.py:225: note: This violates the Liskov substitution principle
- ibis/common/patterns.py:225: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ibis/common/patterns.py:225: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ibis/common/patterns.py:225: note: def __eq__(self, other: object) -> bool:
- ibis/common/patterns.py:225: note: if not isinstance(other, Pattern):
- ibis/common/patterns.py:225: note: return NotImplemented
- ibis/common/patterns.py:225: note: return <logic to compare two Pattern instances>
- ibis/common/patterns.py:657: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ibis/common/patterns.py:657: note: This violates the Liskov substitution principle
- ibis/common/patterns.py:657: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ibis/common/patterns.py:657: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ibis/common/patterns.py:657: note: def __eq__(self, other: object) -> bool:
- ibis/common/patterns.py:657: note: if not isinstance(other, InstanceOf):
- ibis/common/patterns.py:657: note: return NotImplemented
- ibis/common/patterns.py:657: note: return <logic to compare two InstanceOf instances>
- ibis/common/patterns.py:934: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ibis/common/patterns.py:934: note: This violates the Liskov substitution principle
- ibis/common/patterns.py:934: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ibis/common/patterns.py:934: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ibis/common/patterns.py:934: note: def __eq__(self, other: object) -> bool:
- ibis/common/patterns.py:934: note: if not isinstance(other, AnyOf):
- ibis/common/patterns.py:934: note: return NotImplemented
- ibis/common/patterns.py:934: note: return <logic to compare two AnyOf instances>
- ibis/expr/types/generic.py:1294: error: Return type "BooleanValue" of "__eq__" incompatible with return type "bool" in supertype "builtins.object" [override]
- ibis/expr/types/generic.py:1294: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ibis/expr/types/generic.py:1294: note: This violates the Liskov substitution principle
- ibis/expr/types/generic.py:1294: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ibis/expr/types/generic.py:1294: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ibis/expr/types/generic.py:1294: note: def __eq__(self, other: object) -> bool:
- ibis/expr/types/generic.py:1294: note: if not isinstance(other, Value):
- ibis/expr/types/generic.py:1294: note: return NotImplemented
- ibis/expr/types/generic.py:1294: note: return <logic to compare two Value instances>
- ibis/expr/types/generic.py:1301: error: Return type "BooleanValue" of "__ne__" incompatible with return type "bool" in supertype "builtins.object" [override]
- ibis/expr/types/generic.py:1301: error: Argument 1 of "__ne__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ibis/expr/types/generic.py:1301: note: This violates the Liskov substitution principle
- ibis/expr/types/generic.py:1301: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/col.py:185: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/col.py:189: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/arrays/base.py:587: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/arrays/base.py:600: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/generation/hypothesis/__init__.py: note: At top level:
+ src/schemathesis/generation/hypothesis/__init__.py:57: error: Unused "type: ignore" comment [unused-ignore]
+ src/schemathesis/generation/hypothesis/__init__.py: note: In function "setup":
strawberry (https://github.com/strawberry-graphql/strawberry)
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
- ...typeshed_to_test/stdlib/builtins.pyi:140: note: "__init_subclass__" of "object" defined here
+ ...typeshed_to_test/stdlib/builtins.pyi:144: note: "__init_subclass__" of "object" defined here
egglog-python (https://github.com/egraphs-good/egglog-python)
+ python/egglog/runtime.py:715: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/runtime.py:731: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/egraph.py:360: error: Unused "type: ignore[override]" comment [unused-ignore]
+ python/egglog/egraph.py:363: error: Unused "type: ignore[override]" comment [unused-ignore]
scipy-stubs (https://github.com/scipy/scipy-stubs)
+ scipy-stubs/cluster/hierarchy.pyi:90: error: Unused "type: ignore" comment [unused-ignore]
jax (https://github.com/google/jax)
+ jax/_src/basearray.pyi:85: error: Unused "type: ignore" comment [unused-ignore]
+ jax/_src/basearray.pyi:86: error: Unused "type: ignore" comment [unused-ignore]
discord.py (https://github.com/Rapptz/discord.py)
- discord/embeds.py:308: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- discord/embeds.py:308: note: This violates the Liskov substitution principle
- discord/embeds.py:308: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- discord/embeds.py:308: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- discord/embeds.py:308: note: def __eq__(self, other: object) -> bool:
- discord/embeds.py:308: note: if not isinstance(other, Embed):
- discord/embeds.py:308: note: return NotImplemented
- discord/embeds.py:308: note: return <logic to compare two Embed instances>
aiohttp-devtools (https://github.com/aio-libs/aiohttp-devtools)
+ aiohttp_devtools/runserver/utils.py:29: error: Unused "type: ignore" comment [unused-ignore]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/_const.py:194: error: Incompatible types in assignment (expression has type "Callable[[_IDComparable, object], bool]", variable has type "Callable[[object, object], bool]") [assignment]
+ steam/_const.py:194: error: Incompatible types in assignment (expression has type "Callable[[_IDComparable, object], bool]", variable has type "Callable[[object, Any], Any | bool]") [assignment]
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/core/arraylike.pyi:9: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/arraylike.pyi:10: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/arrays/interval.pyi:97: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/arrays/interval.pyi:98: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/_libs/missing.pyi:107: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/_libs/missing.pyi:117: error: Unused "type: ignore" comment [unused-ignore]
operator (https://github.com/canonical/operator)
- ops/jujuversion.py:65: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/jujuversion.py:65: note: This violates the Liskov substitution principle
- ops/jujuversion.py:65: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/jujuversion.py:65: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/jujuversion.py:65: note: def __eq__(self, other: object) -> bool:
- ops/jujuversion.py:65: note: if not isinstance(other, JujuVersion):
- ops/jujuversion.py:65: note: return NotImplemented
- ops/jujuversion.py:65: note: return <logic to compare two JujuVersion instances>
- ops/pebble.py:884: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/pebble.py:884: note: This violates the Liskov substitution principle
- ops/pebble.py:884: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/pebble.py:884: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/pebble.py:884: note: def __eq__(self, other: object) -> bool:
- ops/pebble.py:884: note: if not isinstance(other, Plan):
- ops/pebble.py:884: note: return NotImplemented
- ops/pebble.py:884: note: return <logic to compare two Plan instances>
- ops/pebble.py:946: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/pebble.py:946: note: This violates the Liskov substitution principle
- ops/pebble.py:946: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/pebble.py:946: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/pebble.py:946: note: def __eq__(self, other: object) -> bool:
- ops/pebble.py:946: note: if not isinstance(other, Layer):
- ops/pebble.py:946: note: return NotImplemented
- ops/pebble.py:946: note: return <logic to compare two Layer instances>
- ops/pebble.py:1033: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/pebble.py:1033: note: This violates the Liskov substitution principle
- ops/pebble.py:1033: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/pebble.py:1033: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/pebble.py:1033: note: def __eq__(self, other: object) -> bool:
- ops/pebble.py:1033: note: if not isinstance(other, Service):
- ops/pebble.py:1033: note: return NotImplemented
- ops/pebble.py:1033: note: return <logic to compare two Service instances>
- ops/pebble.py:1148: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/pebble.py:1148: note: This violates the Liskov substitution principle
- ops/pebble.py:1148: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/pebble.py:1148: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/pebble.py:1148: note: def __eq__(self, other: object) -> bool:
- ops/pebble.py:1148: note: if not isinstance(other, Check):
- ops/pebble.py:1148: note: return NotImplemented
- ops/pebble.py:1148: note: return <logic to compare two Check instances>
- ops/pebble.py:1286: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/pebble.py:1286: note: This violates the Liskov substitution principle
- ops/pebble.py:1286: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/pebble.py:1286: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/pebble.py:1286: note: def __eq__(self, other: object) -> bool:
- ops/pebble.py:1286: note: if not isinstance(other, LogTarget):
- ops/pebble.py:1286: note: return NotImplemented
- ops/pebble.py:1286: note: return <logic to compare two LogTarget instances>
- ops/model.py:2191: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/model.py:2191: note: This violates the Liskov substitution principle
- ops/model.py:2191: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/model.py:2191: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/model.py:2191: note: def __eq__(self, other: object) -> bool:
- ops/model.py:2191: note: if not isinstance(other, StatusBase):
- ops/model.py:2191: note: return NotImplemented
- ops/model.py:2191: note: return <logic to compare two StatusBase instances>
- ops/framework.py:116: error: Argument 1 of "__eq__" is incompatible with supertype "builtins.object"; supertype defines the argument type as "object" [override]
- ops/framework.py:116: note: This violates the Liskov substitution principle
- ops/framework.py:116: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/framework.py:116: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/framework.py:116: note: def __eq__(self, other: object) -> bool:
- ops/framework.py:116: note: if not isinstance(other, Handle):
- ops/framework.py:116: note: return NotImplemented
- ops/framework.py:116: note: return <logic to compare two Handle instances>
|
This was referenced Jan 30, 2026
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 #15345
Currently,
objectdefinesthis causes lots of
type: ignore[override]errors because everything subclassesobject, but many classes may:This experiment tests what happens if we loosen the type of
object.__eq__andobject.__ne__After experimentation, the best choice seems to be: