-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Support dataclasses.InitVar
#19527
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
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 197 | 1 |
invalid-assignment |
0 | 15 | 1 |
| Total | 0 | 212 | 2 |
crates/ty_python_semantic/resources/mdtest/type_qualifiers/initvar.md
Outdated
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/type_qualifiers/initvar.md
Outdated
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/type_qualifiers/initvar.md
Outdated
Show resolved
Hide resolved
|
Here are some mypy issues regarding
There are also quite a few dataclass/ |
|
Hm.. that would be difficult to support. And that example doesn't even appear to work at runtime for me (TypeError: non-default argument '_prop' follows default argument 'prop') Okay. Made some changes to support that scenario, and added a test. |
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Oh, thank you! Though I wasn't necessarily asking for any changes to the implementation here, just for an explicit test so it was obvious what our behaviour was. Sorry if I was unclear there. Mypy decided that its behaviour here was a feature rather than a bug, so I think sticking with what you had before would have been defensible -- you could argue that creating an implicit instance variable by assigning to that attribute in an instance method contradicts the explicit declaration of the variable as That said, I also think the new behaviour you've implemented is fine. It obviously works fine at runtime, and we're generally more permissive than other type checkers when it comes to our understanding of the set of implicit instance variables a class has -- being more permissive here feels in line with our general philosophy there. |
carljm
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.
Nice!
…hlight * 'main' of https://github.com/astral-sh/ruff: [ty] Minor: fix incomplete docstring (astral-sh#19534) [ty] Move server tests as integration tests (astral-sh#19522) [`ruff`] Offer fixes for `RUF039` in more cases (astral-sh#19065) [ty] Support `dataclasses.InitVar` (astral-sh#19527) [`ruff`] Fix `RUF033` breaking with named default expressions (astral-sh#19115) Update pre-commit hook name (astral-sh#19530) Bump 0.12.5 (astral-sh#19528) [ty] Rename type_api => ty_extensions (astral-sh#19523) [ty] Added support for "go to references" in ty playground. (astral-sh#19516) [ty] Return a tuple spec from the iterator protocol (astral-sh#19496) [ty] Exhaustiveness checking & reachability for `match` statements (astral-sh#19508) [ty] Fix narrowing and reachability of class patterns with arguments (astral-sh#19512)
* main: [ty] Added support for "document highlights" language server feature. (astral-sh#19515) Add support for specifying minimum dots in detected string imports (astral-sh#19538) [ty] Minor: fix incomplete docstring (astral-sh#19534) [ty] Move server tests as integration tests (astral-sh#19522) [`ruff`] Offer fixes for `RUF039` in more cases (astral-sh#19065) [ty] Support `dataclasses.InitVar` (astral-sh#19527) [`ruff`] Fix `RUF033` breaking with named default expressions (astral-sh#19115) Update pre-commit hook name (astral-sh#19530) Bump 0.12.5 (astral-sh#19528) [ty] Rename type_api => ty_extensions (astral-sh#19523) [ty] Added support for "go to references" in ty playground. (astral-sh#19516) # Conflicts: # crates/ty_server/src/server/api/requests.rs # crates/ty_server/tests/e2e/snapshots/e2e__initialize__initialization.snap # crates/ty_server/tests/e2e/snapshots/e2e__initialize__initialization_with_workspace.snap
## Summary I saw that this creates a lot of false positives in the ecosystem, and it seemed to be relatively easy to add basic support for this. Some preliminary work on this was done by @InSyncWithFoo — thank you. part of astral-sh/ty#111 ## Ecosystem analysis The results look good. ## Test Plan New Markdown tests --------- Co-authored-by: InSync <insyncwithfoo@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Summary
I saw that this creates a lot of false positives in the ecosystem, and it seemed to be relatively easy to add basic support for this.
Some preliminary work on this was done by @InSyncWithFoo — thank you.
part of astral-sh/ty#111
Ecosystem analysis
The results look good.
Test Plan
New Markdown tests