Skip to content

Incompatible type with generic dataclasses inheritance #7715

Closed
@Eugene-1984

Description

@Eugene-1984

The following MWE:

from typing import Generic, TypeVar
import dataclasses

T = TypeVar('T')

@dataclasses.dataclass()
class A(Generic[T]):
    attr: T

A(attr=0)  # OK!

@dataclasses.dataclass()
class B(A[float]):
    ...

B(attr=float(0))
# Argument "attr" to "B" has incompatible type "float"; expected "T"

fails with "Argument "attr" to "B" has incompatible type "float"; expected "T"" error in mypy. But the B class specifies T to be float, how to fix that error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions