Skip to content

Emit a diagnostic on TypedDict classes decorated with @dataclass #2527

@MeGaGiGaGon

Description

@MeGaGiGaGon

This should be an error, since using the resulting class like a dataclass will always fail at runtime. It would also be a useful diagnostic to have because it can happen (and has to me a couple times) while refactoring a dataclass to a TypedDict, but forgetting to remove the decorator. Maybe could be extended to all decorators? Unsure, but dataclass would be the most useful.
https://play.ty.dev/2ddb5461-df08-43fc-88d6-8be63319220b

from typing import TypedDict
from dataclasses import dataclass

@dataclass
class Foo(TypedDict):
    x: int

print(Foo(1))  # No error because ty thinks it is a dataclass, but fails at runtime

Metadata

Metadata

Assignees

Labels

dataclassesIssues relating to dataclasses and dataclass_transformtypeddict

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions