-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[ty] Support dataclass_transform as a function call
#22378
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
base: main
Are you sure you want to change the base?
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
e016ff5 to
7f675dd
Compare
|
7f675dd to
bace8c4
Compare
|
(The |
|
|
||
| // If the return type is class-like and the first argument is a | ||
| // class, return it with dataclass params applied. Otherwise, | ||
| // return a `DataclassDecorator` for application to a class later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong. It's intended to address cases like:
@dataclass_transform()
def hydrated_dataclass(target: type, *, frozen: bool = False) -> Callable[[type[T]], type[T]]:
def decorator(cls: type[T]) -> type[T]:
return cls
return decorator
@hydrated_dataclass(SomeConfig, frozen=True)
class MyConfig:
passIf we make this change without this declared return type handling, then hydrated_dataclass(SomeConfig, frozen=True) returns type[SomeConfig] with dataclass params, and we apply that as a decorator.
Summary
Instead of just as a decorator.
Closes astral-sh/ty#2319.