[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:
David Peter
2025-09-05 10:12:40 +02:00
committed by GitHub
parent 7509d376eb
commit 9e45bfa9fd
2 changed files with 12 additions and 11 deletions

View File

@@ -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(),