Skip to content

1.6.1 > 1.7.0 and 1.7.1 regression in for "broken" dataclasses #16580

Open
@DanielNoord

Description

@DanielNoord

Bug Report

When type checking the following code the output changes depending on whether you use 1.6.0 or 1.7.1.

To Reproduce

from dataclasses import dataclass


@dataclass(frozen=True)
class A:
    attr_one: int
    attr_two: int | None


@dataclass(frozen=True)
class B(A):
    attr_two = None


instance = B(attr_one=1)
print(instance.attr_two)

Playground: https://mypy-play.net/?mypy=1.7.0&python=3.11&gist=f74740e7a7ef6bf0c9f88175a988aed5

The code is likely not doing what the author expects it to do, but the new message is wrong as attr_two can be referenced and is certainly not an instance of B.

Expected Behavior

main.py:15: error: Missing positional argument "attr_two" in call to "B"  [call-arg]
Found 1 error in 1 file (checked 1 source file)

Actual Behavior

main.py:15: error: Missing positional argument "attr_two" in call to "B"  [call-arg]
main.py:16: error: "B" not callable  [operator]
Found 2 errors in 1 file (checked 1 source file)

Your Environment
master branch on Playground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions