Skip to content
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

Inheriting from two data classes causes error Definition of "__match_args__" in base class "A" is incompatible with definition in base class "B" #12349

Closed
dcermak opened this issue Mar 14, 2022 · 1 comment · Fixed by #12411
Assignees
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement

Comments

@dcermak
Copy link

dcermak commented Mar 14, 2022

Bug Report

When creating a derived class that inherits from two data classes, mypy will immediately flag the derived class with Definition of "__match_args__" in base class "A" is incompatible with definition in base class "B"

To Reproduce

  1. Create the following file
from dataclasses import dataclass

@dataclass
class A:
    prop_a: str

@dataclass
class B:
    prop_b: bool

class Derived(A, B):
    pass
  1. Run mypy . and observe the error:
test.py:11: error: Cannot override final attribute "__match_args__" (previously declared in base class "B")
test.py:11: error: Cannot override writable attribute "__match_args__" with a final one
test.py:11: error: Definition of "__match_args__" in base class "A" is incompatible with definition in base class "B"
Found 3 errors in 1 file (checked 1 source file)

Expected Behavior

Given that I did not set __match_args__ myself makes this error really hard to understand. I would have expected no such error to occur, especially as the code should work for older Python versions that don't support pattern matching yet.

Your Environment

  • Mypy version used: 0.940
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10
  • Operating system and version: Linux, Fedora 35
@dcermak dcermak added the bug mypy got something wrong label Mar 14, 2022
@JelleZijlstra JelleZijlstra added the topic-match-statement Python 3.10's match statement label Mar 19, 2022
@JukkaL JukkaL self-assigned this Mar 21, 2022
@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 21, 2022

Looks like the same bug as #12008

JukkaL added a commit that referenced this issue Mar 21, 2022
…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.
JukkaL added a commit that referenced this issue Mar 22, 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.
JukkaL added a commit that referenced this issue 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants