Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
binishkaspar opened this issue Feb 3, 2021 · 1 comment
Labels
crash topic-dataclasses topic-inheritance Inheritance and incompatible overrides

Comments

@binishkaspar
Copy link

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
@AlexWaygood AlexWaygood added topic-dataclasses topic-inheritance Inheritance and incompatible overrides labels Mar 24, 2022
@AlexWaygood
Copy link
Member

Here's a minimized repro:

from typing import TypeVar, Generic
from dataclasses import dataclass

DriveTypeT = TypeVar('DriveTypeT')

@dataclass
class Driver(Generic[DriveTypeT]):
    car: DriveTypeT

@dataclass
class Foo(Driver['Bar']): ...

@dataclass
class Bar(Driver[Foo]): ...

This reveals it to be exactly the same crash as #12685. Happily, this was fixed in #12762; and since the stack trace and minimized repro are both identical, I don't think we need to add another test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-dataclasses topic-inheritance Inheritance and incompatible overrides
Projects
None yet
Development

No branches or pull requests

2 participants