8000 mypy crashes on callable frozen dataclass · Issue #12084 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content
mypy crashes on callable frozen dataclass #12084
Closed
@alexei

Description

@alexei

Crash Report

mypy crashes on callable frozen dataclass

Traceback

➜  mypy-bug poetry run mypy mypy_bug/case_3.py --show-traceback
mypy_bug/case_3.py:14: 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: 0.931
Traceback (most recent call last):
  File "mypy/semanal.py", line 5142, in accept
  File "mypy/nodes.py", line 1005, in accept
  File "mypy/semanal.py", line 1105, in visit_class_def
  File "mypy/semanal.py", line 1184, in analyze_class
  File "mypy/semanal.py", line 1193, in analyze_class_body_common
  File "mypy/semanal.py", line 1239, in apply_class_plugin_hooks
  File "mypy/plugins/dataclasses.py", line 489, in dataclass_class_maker_callback
  File "mypy/plugins/dataclasses.py", line 194, in transform
  File "mypy/plugins/dataclasses.py", line 431, in _freeze
AssertionError: 
mypy_bug/case_3.py:14: : note: use --pdb to drop into pdb

To Reproduce

from dataclasses import dataclass
from typing import Any, Callable

# here both `Parent` and `Child` are frozen dataclasses

@dataclass(frozen=True)
class Parent:
    __call__: Callable[..., None]

    def __call__(self, *args: Any, **kwargs: Any) -> None:  # type: ignore
        raise NotImplementedError


@dataclass(frozen=True)
class Child(Parent):
    def __call__(self, value: int) -> None:
        ...

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.0
  • Operating system and version: macOS Catalina (10.15)

I'm using "Guido's hack" from #9560 (comment) which does work in other circumstances:

from typing import Any, Callable

# here both `Parent` and `Child` are "regular" classes

class Parent:
    __call__: Callable[..., None]

    def __call__(self, *args: Any, **kwargs: Any) -> None:  # type: ignore
        raise NotImplementedError


class Child(Parent):
    def __call__(self, value: int) -> None:
        ...
from dataclasses import dataclass
from typing import Any, Callable

# here `Parent` is a frozen dataclass, but `Child` is not

@dataclass(frozen=True)
class Parent:
    __call__: Callable[..., None]

    def __call__(self, *args: Any, **kwargs: Any) -> None:  # type: ignore
        raise NotImplementedError


class Child(Parent):
    def __call__(self, value: int) -> None:
        ...
from dataclasses import dataclass
from typing import Any, Callable

# here both `Parent` and `Child` are dataclasses, but not frozen

@dataclass
class Parent:
    __call__: Callable[..., None]

    def __call__(self, *args: Any, **kwargs: Any) -> None:  # type: ignore
        raise NotImplementedError


@dataclass
class Child(Parent):
    def __call__(self, value: int) -> None:
        ...

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0