-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Check method definitions on subclasses for Liskov violations #21436
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7570094
[ty] Check method definitions on subclasses for Liskov violations
AlexWaygood 4f3d256
fixes
AlexWaygood 7f053ea
Fix incorrect identification of where the overridden method was defined
AlexWaygood e127c25
disambiguate class names where necessary
AlexWaygood 96b2535
try to optimize
AlexWaygood e1764c7
regen
AlexWaygood 935640d
qualified-name cleanup
AlexWaygood 6d296a7
more reliable subdiagnostic
AlexWaygood da0cdfc
snapshots and docs
AlexWaygood cd2d59c
more subdiagnostics and docs
AlexWaygood 3522623
move submodule
AlexWaygood 65f1a20
remove done TODO
AlexWaygood 7f918d7
add submodule doc-comment
AlexWaygood e4b2174
Merge branch 'main' into alex/basic-liskov
AlexWaygood 4f18e49
further improve diagnostics
AlexWaygood a5f0983
Merge branch 'main' into alex/basic-liskov
AlexWaygood 8c03f3f
fix bugs, add many more tests, hopefully optimize?
AlexWaygood 7f7169a
Merge branch 'main' into alex/basic-liskov
AlexWaygood 7d57fee
moar tests
AlexWaygood 76adbcb
Apply suggestions from code review
AlexWaygood d586e66
Merge branch 'main' into alex/basic-liskov
AlexWaygood da211a9
Merge branch 'alex/basic-liskov' of https://github.com/astral-sh/ruff…
AlexWaygood 1d6c816
more review comments
AlexWaygood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 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 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 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary to decide in this PR, but I wonder if we should special-case ignoring
object.__setattr__for Liskov purposes (and separately implement validation of a correct__setattr__signature). TBH I'm not even sure why typeshed hasobject.__setattr__, and I don't think there is any soundness need for subclasses ofobjectto respect Liskov compatibility with theobject.__setattr__definition in typeshed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think you're right.
I was also wondering about special-case ignoring
object.__hash__. It's obviously common to define unhashable classes in Python, and it's often the correct thing to do to add__hash__ = Noneif your class is mutable. Having a type checker yell at you every time you have to do that has never felt helpful to me.I can propose them both (either together or separately) as followups. I'd rather keep them out of this PR, since either special case (while, IMO, well-motivated) would be a deviation from the behaviour of other type checkers.