-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix inheritance false positives with dataclasses/attrs #12411
Conversation
This comment has been minimized.
This comment has been minimized.
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') |
No, but it shouldn't be hard to also fix them. |
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 |
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).
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]
|
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).
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.