mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] Support dataclasses.InitVar
(#19527)
## 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 https://github.com/astral-sh/ty/issues/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>
This commit is contained in:
parent
1079975b35
commit
dc6be457b5
5 changed files with 336 additions and 57 deletions
|
@ -244,7 +244,7 @@ pub(crate) fn class_symbol<'db>(
|
|||
ConsideredDefinitions::EndOfScope,
|
||||
);
|
||||
|
||||
if !place_and_quals.place.is_unbound() {
|
||||
if !place_and_quals.place.is_unbound() && !place_and_quals.is_init_var() {
|
||||
// Trust the declared type if we see a class-level declaration
|
||||
return place_and_quals;
|
||||
}
|
||||
|
@ -524,6 +524,11 @@ impl<'db> PlaceAndQualifiers<'db> {
|
|||
self.qualifiers.contains(TypeQualifiers::CLASS_VAR)
|
||||
}
|
||||
|
||||
/// Returns `true` if the place has a `InitVar` type qualifier.
|
||||
pub(crate) fn is_init_var(&self) -> bool {
|
||||
self.qualifiers.contains(TypeQualifiers::INIT_VAR)
|
||||
}
|
||||
|
||||
/// Returns `Some(…)` if the place is qualified with `typing.Final` without a specified type.
|
||||
pub(crate) fn is_bare_final(&self) -> Option<TypeQualifiers> {
|
||||
match self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue