Fix __contains__ and __eq__ override signatures#649
Open
bizfsc wants to merge 1 commit intocanopen-python:masterfrom
Open
Fix __contains__ and __eq__ override signatures#649bizfsc wants to merge 1 commit intocanopen-python:masterfrom
bizfsc wants to merge 1 commit intocanopen-python:masterfrom
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Change method signatures to accept 'object' as required by the Liskov substitution principle (Mapping/Container/object supertypes). For __eq__, return NotImplemented for incompatible types instead of raising AttributeError. For __contains__ in SdoArray, add isinstance check to handle non-int arguments gracefully.
94cdcc7 to
3e4453a
Compare
This was referenced Apr 29, 2026
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.
Fix
__contains__and__eq__override signatures to satisfy the Liskov substitution principle.Problem
mypy reports
[override]errors because__contains__and__eq__methods use specific types (Union[int, str],ODRecord, etc.) instead ofobjectas required by theMapping,Container, andobjectsupertypes.Changes
canopen/objectdictionary/__init__.pyObjectDictionary.__contains__: acceptobjectinstead ofUnion[int, str]ODRecord.__contains__: acceptobjectinstead ofUnion[int, str]ODRecord.__eq__: acceptobject, returnNotImplementedfor non-ODRecordODArray.__eq__: acceptobject, returnNotImplementedfor non-ODArrayODVariable.__eq__: acceptobject, returnNotImplementedfor non-ODVariablecanopen/sdo/base.pySdoBase.__contains__: acceptobjectinstead ofUnion[int, str]SdoRecord.__contains__: acceptobjectinstead ofUnion[int, str]SdoArray.__contains__: acceptobjectinstead ofint, addisinstanceguardImpact
Eliminates all 18
[override]mypy errors (95 → 77 remaining).