python / python/mypy

1.6.1 > 1.7.0 and 1.7.1 regression in for "broken" ``dataclasses``

Open
#16,580 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-dataclasses
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the dataclass example in the issue or its linked mypy-playground configuration, comparing the reported diagnostics across the affected versions. Trace the dataclass handling that produces the erroneous "B not callable" message; done means the example reports only the missing attr_two argument as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.