Skip to content

[BUG] Incorrect type inference with dataclass_transform and generics / decorators #2319

@liblaf

Description

@liblaf

Summary

When using @dataclass_transform() in combination with generics and overloads, ty appears to infer the wrong type for the result of the dataclass-like decorator. This differs from the behavior of the standard dataclasses.dataclass function:

Example / Minimal Repro:

import dataclasses
from collections.abc import Callable
from typing import dataclass_transform, overload, reveal_type

@dataclass_transform()
@overload
def func[T: type](cls: T) -> T: ...
@dataclass_transform()
@overload
def func[T: type]() -> Callable[[T], T]: ...
def func[T: type](cls: T | None = None) -> T | Callable[[T], T]:
    raise NotImplementedError

class A: ...

B = dataclasses.dataclass(A)
reveal_type(B)  # `<class 'A'>` as expected

C = func(A)
# actual: `<decorator produced by dataclass-like function>`
# expected: `<class 'A'>`
reveal_type(C)

Expected Behavior

The result of func(A) should be inferred as <class 'A'>, matching the behavior of the standard dataclasses.dataclass application.

Actual Behavior

'ty' reports <decorator produced by dataclass-like function> instead of <class 'A'> for reveal_type(C).

Environment


Let me know if further details or logs are needed!

Version

ty 0.0.8 (aa7559d 2025-12-29)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdataclassesIssues relating to dataclasses and dataclass_transform

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions