Skip to content

mypy crashes on callable frozen dataclass #12084

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

fromdataclassesimportdataclassfromtypingimportAny, Callable# here both `Parent` and `Child` are frozen dataclasses@dataclass(frozen=True)classParent:
__call__: Callable[..., None]
def__call__(self, *args: Any, **kwargs: Any) ->None: # type: ignoreraiseNotImplementedError@dataclass(frozen=True)classChild(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:

fromtypingimportAny, Callable# here both `Parent` and `Child` are "regular" classesclassParent:
__call__: Callable[..., None]
def__call__(self, *args: Any, **kwargs: Any) ->None: # type: ignoreraiseNotImplementedErrorclassChild(Parent):
def__call__(self, value: int) ->None:
...
fromdataclassesimportdataclassfromtypingimportAny, Callable# here `Parent` is a frozen dataclass, but `Child` is not@dataclass(frozen=True)classParent:
__call__: Callable[..., None]
def__call__(self, *args: Any, **kwargs: Any) ->None: # type: ignoreraiseNotImplementedErrorclassChild(Parent):
def__call__(self, value: int) ->None:
...
fromdataclassesimportdataclassfromtypingimportAny, Callable# here both `Parent` and `Child` are dataclasses, but not frozen@dataclassclassParent:
__call__: Callable[..., None]
def__call__(self, *args: Any, **kwargs: Any) ->None: # type: ignoreraiseNotImplementedError@dataclassclassChild(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