Skip to content

Internal Error found on v0.800 when using Generic Inheritance for dataclass #10014

Closed
@binishkaspar

Description

@binishkaspar

Crash Report

Following code raises INTERNAL ERROR on version 0.800 but not on 0.790

DRIVE_TYPE = TypeVar('DRIVE_TYPE', bound='Driver')

# This WORKS
# DRIVER_STATE_TYPE = TypeVar('DRIVER_STATE_TYPE', bound='DriverState')


@dataclass
class DriverState(Generic[DRIVE_TYPE]):
    driver: DRIVE_TYPE
    pid: str = ''


# This doesn't work
DRIVER_STATE_TYPE = TypeVar('DRIVER_STATE_TYPE', bound='DriverState')


@dataclass
class Driver(Generic[DRIVER_STATE_TYPE]):
    config: DRIVER_STATE_TYPE


@dataclass
class ESState(DriverState['ESDriver']):
    special_name: str = 'ES Driver'


@dataclass
class ESDriver(Driver[
    ESState
]):
    def name(self) -> None:
        print(self.config.special_name)

Is it because supertype not recursively expanded? I believe this has something to do with the fix #7520.

Traceback

mypyissue.py:32: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.800
Traceback (most recent call last):
  File "mypy/semanal.py", line 4835, in accept
  File "mypy/nodes.py", line 950, in accept
  File "mypy/semanal.py", line 1048, in visit_class_def
  File "mypy/semanal.py", line 1125, in analyze_class
  File "mypy/semanal.py", line 1134, in analyze_class_body_common
  File "mypy/semanal.py", line 1180, in apply_class_plugin_hooks
  File "mypy/plugins/dataclasses.py", line 361, in dataclass_class_maker_callback
  File "mypy/plugins/dataclasses.py", line 100, in transform
  File "mypy/plugins/dataclasses.py", line 302, in collect_attributes
  File "mypy/plugins/dataclasses.py", line 86, in expand_typevar_from_subtype
  File "mypy/typeops.py", line 165, in map_type_from_supertype
  File "mypy/maptype.py", line 24, in map_instance_to_supertype
  File "mypy/maptype.py", line 37, in map_instance_to_supertypes
  File "mypy/maptype.py", line 82, in map_instance_to_direct_supertypes
  File "mypy/expandtype.py", line 16, in expand_type
  File "mypy/types.py", line 833, in accept
  File "mypy/expandtype.py", line 85, in visit_instance
  File "mypy/expandtype.py", line 145, in expand_types
  File "mypy/types.py", line 1942, in accept
AssertionError: 
mypyissue.py:32: : note: use --pdb to drop into pdb

Your Environment

  • Mypy version used: v0.800
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: Python 3.8.5
  • Operating system and version: MacOS

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions