Skip to content

Conversation

@JukkaL
Copy link
Collaborator

Multiple inheritance from dataclasses and attrs classes works at runtime,
so don't complain about __match_args__ or __attrs_attrs__ which tend
to have incompatible types in subclasses.

Fixes#12349. Fixes#12008. Fixes#12065.

…sses Multiple inheritance from dataclasses and attrs classes works at runtime, so don't complain about `__match_args__` or `__attrs_attrs__` which tend to have incompatible types in subclasses. Fixes#12349. Fixes#12008. Fixes#12065.
@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 21, 2022

Does this also fix the false positive in the following code, which currently prevents typeshed from adding __match_args__ annotations to stdlib/_ast.pyi (discussed here: #12203 (comment))?

classAST: __match_args__= () classstmt(AST): ... classAnnAssign(stmt): __match_args__= ('target', 'annotation', 'value', 'simple')

@JukkaL
Copy link
CollaboratorAuthor

Does this also fix the false positive in the following code, ....

No, but it shouldn't be hard to also fix them.

@JukkaLJukkaL marked this pull request as draft March 21, 2022 16:04
@jhance
Copy link
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 final (name TBD) that indicates the field is special in the same way __slots__ is, then that would be preferable (and also clearer because it doesn't centralize the list of special cases)

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).
@JukkaLJukkaL marked this pull request as ready for review March 22, 2022 14:27
@github-actions
Copy link
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).
@JukkaLJukkaL merged commit e0f16ed into masterMar 22, 2022
@JukkaLJukkaL deleted the dataclass-inheritance branch March 22, 2022 16:26
JukkaL added a commit that referenced this pull request Mar 23, 2022
Multiple inheritance from dataclasses and attrs classes works at runtime, so don't complain about `__match_args__` or `__attrs_attrs__` which tend to have incompatible types in subclasses. Fixes#12349. Fixes#12008. Fixes#12065.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants

@JukkaL@AlexWaygood@jhance