Skip to content

[1.16 regression] Crashes on a combination of dataclass inheritance, InitVar, and properties. #19443

Description

@kkorotkov

Crash Report

mypy started crashing on the code below starting with version 1.16.0 — it was still working fine in 1.15.0.

Traceback

# mypy mypy-internal-error.py --show-traceback
mypy-internal-error.py:27: error: Name "value" already defined on line 22 [no-redef]
mypy-internal-error.py:27: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.17.0
Traceback (most recent call last):
File "mypy/checker.py", line 584, in accept
File "mypy/nodes.py", line 610, in accept
File "mypy/checker.py", line 657, in visit_overloaded_func_def
File "mypy/checker.py", line 739, in _visit_overloaded_func_def
File "mypy/checker.py", line 2081, in check_method_override
File "mypy/checker.py", line 2119, in check_method_or_accessor_override_for_base
File "mypy/checker.py", line 2172, in check_method_override_for_base_with_name
AssertionError:
mypy-internal-error.py:27: : note: use --pdb to drop into pdb

To Reproduce

from dataclasses import InitVar, dataclass, field
from typing import Callable
@dataclass
class ClassA:
_value: int
@property
def value(self) -> int:
return self._value
@value.setter
def value(self, value: int):
self._value = value
@dataclass
class ClassB(ClassA):
getter: Callable[[], int]
setter: Callable[[int], None]
value: InitVar[int]
def __post_init__(self, value: int):
self.value = value
@property
def value(self) -> int:
return self.getter()
@value.setter
def value(self, value: int):
self.setter(value)

Your Environment

  • Mypy version used: >=1.16.0
  • Mypy command-line flags: mypy mypy-internal-error.py --show-traceback
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10
  • Operating system and version: macOS 15.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions