-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Detect overloads decorated with @dataclass_transform
#17835
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
Conversation
|
|
This is as of now incomplete, in that it only handles the cases where the function which is supposed to act like a dataclass decorator is being used in a "call" context, like so: @versioned_class(version=2)
class D2:
x: strThis PR does not yet fix cases where @versioned_class
class D1:
x: strThis is because, in the later case, logic to determine if the ruff/crates/ty_python_semantic/src/types/infer.rs Lines 2101 to 2106 in e95130a
For the @dhruvmanila I would appreciate any thoughts on how to handle this case. We will need to probably add in some custom behavior to "carry over" the |
0f7d49f to
35f9adb
Compare
|
I (ab)used |
35f9adb to
518ef57
Compare
|
Thank you very much for working on this! I am planning to do a full review soon. One thing that I hoped would be happening with this PR is that we understand But it does not seem to work yet, on your branch:
import strawberry
@strawberry.type
class User:
name: str
age: int
User(name="Patrick", age=100)It might be interesting to understand why this does not work yet (not implying that you need to do this, I can also look into it when I get around to it). |
|
Interesting. I would certainly be interested in investigating this, but it does not give any errors for me though: [~/code/ruff] $ git reset --hard origin/dataclass
HEAD is now at 518ef57c2 fix typo in comment
[~/code/ruff] $ git lol -3
518ef57c2 (HEAD -> dataclass, origin/dataclass) fix typo in comment
837ad29b4 fix name load usage also
828248142 [ty] Detect overloads decorated with `@dataclass_transform`
[~/code/ruff] $ uv run --no-project --with strawberry-graphql cargo run --bin ty -- check /tmp/strawberry_test.py
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.51s
Running `target/debug/ty check /tmp/strawberry_test.py`
All checks passed!Just to confirm, you're on the latest version of this branch right? I had force pushed a couple of times here. |
Oh, indeed. I must have done something wrong when switching branches. It works as expected — nice! I expected more ecosystem changes in strawberry, but it looks like in mypy_primer, we're only checking the "strawberry" subfolder, and not strawberry's tests, which would contain many examples. The occurrences of Sorry for the distraction. |
|
Hmmph, I don't understand how |
Sorry, I didn't mean to imply that we should change that. I think it's fine as is. It is configured here: https://github.com/hauntsaninja/mypy_primer/blob/a4e8faf6832df707a36a4225f88ec4dc04733e96/mypy_primer/projects.py#L1517 We use mypy_primer to run ty across a set of open source projects (the ones you see in that linked file). Once for the version on |
sharkdp
left a comment
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.
This looks great — thank you very much!
Summary
Fixes #17541
Before this change, in the case of overloaded functions,
@dataclass_transformwas detected only when applied to the implementation, not the overloads.However, the spec also allows this decorator to be applied to any of the overloads as well.
With this PR, we start handling
@dataclass_transforms applied to overloads.Test Plan
Fixed existing TODOs in the test suite.