Fix inheritance false positives with dataclasses/attrs#12411
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
Member
|
Does this also fix the false positive in the following code, which currently prevents typeshed from adding class AST:
__match_args__ = ()
class stmt(AST): ...
class AnnAssign(stmt):
__match_args__ = ('target', 'annotation', 'value', 'simple') |
Collaborator
Author
No, but it shouldn't be hard to also fix them. |
Collaborator
|
It seems like it is not good that a plugin depends on a magic list in mypy. If it is possible to add a parameter similar to |
JukkaL
added a commit
that referenced
this pull request
Mar 22, 2022
Allow subclasses to override `__match_args__` freely, and don't require `__match_args__` to be final. This matches runtime behavior. For example, if `B` subclasses `A`, `case A(...)` also matches instances of `B`, using the `__match_args__` from `A`. The issue was brough up by @AlexWaygood in #12411 (comment).
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: rotki (https://github.com/rotki/rotki)
+ rotkehlchen/chain/ethereum/modules/adex/adex.py:808: error: Unused "type: ignore" comment
steam.py (https://github.com/Gobot1234/steam.py)
- steam/profile.py:204: error: Cannot override final attribute "__match_args__" (previously declared in base class "EquippedProfileItems") [misc]
- steam/profile.py:204: error: Cannot override writable attribute "__match_args__" with a final one [misc]
- steam/profile.py:204: error: Definition of "__match_args__" in base class "ProfileInfo" is incompatible with definition in base class "EquippedProfileItems" [misc]
|
JukkaL
added a commit
that referenced
this pull request
Mar 22, 2022
Allow subclasses to override `__match_args__` freely, and don't require `__match_args__` to be final. This matches runtime behavior. For example, if `B` subclasses `A`, `case A(...)` also matches instances of `B`, using the `__match_args__` from `A`. The issue was brough up by @AlexWaygood in #12411 (comment).
jhance
approved these changes
Mar 22, 2022
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.
Multiple inheritance from dataclasses and attrs classes works at runtime,
so don't complain about
__match_args__or__attrs_attrs__which tendto have incompatible types in subclasses.
Fixes #12349. Fixes #12008. Fixes #12065.