KEMBAR78
Overriding __init__ in dataclass crashes mypy · Issue #8015 · python/mypy · GitHub
Skip to content

Overriding __init__ in dataclass crashes mypy #8015

@beckjake

Description

@beckjake

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?
    A bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

import dataclasses

@dataclasses.dataclass
class MyClass:
    a: dataclasses.InitVar[int]
    _a: int = dataclasses.field(init=False)

    def __post_init__(self, a: int) -> None:
        self._a = a

@dataclasses.dataclass
class MySubClass(MyClass):
    b: int = dataclasses.field(init=False)

    def __post_init__(self, a: int) -> None:
        super().__post_init__(a)
        self.b = a + 1

@dataclasses.dataclass(init=False)
class MyFinalClass(MySubClass):
    c: int

    def __init__(self, a: int, c: int) -> None:
        super().__init__(a)
        self.c = c + self.b
  • What is the actual behavior/output?
    Mypy crashes with INTERNAL ERROR: maximum semantic analysis iteration count reached Found 1 error in 1 file (checked 1 source file):

  • What is the behavior/output you expect?

Really anything but a crash would be good! Ideally it would accept my __init__ override.

  • What are the versions of mypy and Python you are using?
    Python: 3.6.5, 3.8.0 (mypy 0.740 only)

    Do you see the same issue after installing mypy from Git master?

0.740 and git master (253bdb5)

  • What are the mypy flags you are using? (For example --strict-optional)

No flags. Using --show-traceback didn't provide any extra information, and --verbose didn't seem to add anything of value.

  • If mypy crashed with a traceback, please paste
    the full traceback below.

Here's the "Deferral trace"

Deferral trace:
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
    crash_mypy:27
crash_mypy.py: error: INTERNAL ERROR: maximum semantic analysis iteration count reached
Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions