-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#22378Labels
bugSomething isn't workingSomething isn't workingdataclassesIssues relating to dataclasses and dataclass_transformIssues relating to dataclasses and dataclass_transform
Milestone
Description
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
- ty command: ty check main.py
- playground link: https://play.ty.dev/9cb27674-5bb8-4cb5-abe4-f49ec8cd2fb2
Let me know if further details or logs are needed!
Version
ty 0.0.8 (aa7559d 2025-12-29)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdataclassesIssues relating to dataclasses and dataclass_transformIssues relating to dataclasses and dataclass_transform