mirror of
https://github.com/astral-sh/ruff
synced 2026-01-07 14:44:17 -05:00
[ty] Cover full range of annotated assignments (#20261)
## Summary An annotated assignment `name: annotation` without a right-hand side was previously not covered by the range returned from `DefinitionKind::full_range`, because we did expand the range to include the right-hand side (if there was one), but failed to include the annotation. ## Test Plan Updated snapshot tests
This commit is contained in:
@@ -769,13 +769,14 @@ impl DefinitionKind<'_> {
|
||||
target_range.cover(value_range)
|
||||
}
|
||||
DefinitionKind::AnnotatedAssignment(assign) => {
|
||||
let target_range = assign.target.node(module).range();
|
||||
let mut full_range = assign.target.node(module).range();
|
||||
full_range = full_range.cover(assign.annotation.node(module).range());
|
||||
|
||||
if let Some(ref value) = assign.value {
|
||||
let value_range = value.node(module).range();
|
||||
target_range.cover(value_range)
|
||||
} else {
|
||||
target_range
|
||||
full_range = full_range.cover(value.node(module).range());
|
||||
}
|
||||
|
||||
full_range
|
||||
}
|
||||
DefinitionKind::AugmentedAssignment(aug_assign) => aug_assign.node(module).range(),
|
||||
DefinitionKind::For(for_stmt) => for_stmt.target.node(module).range(),
|
||||
|
||||
Reference in New Issue
Block a user