mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:14:52 +00:00
[ty] Cover full range of annotated assignments (#20261)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
## 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:
parent
7509d376eb
commit
9e45bfa9fd
2 changed files with 12 additions and 11 deletions
|
@ -47,7 +47,7 @@ error[invalid-named-tuple]: NamedTuple field without default value cannot follow
|
||||||
| --------------------- Earlier field `altitude` defined here with a default value
|
| --------------------- Earlier field `altitude` defined here with a default value
|
||||||
5 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `latitud…
|
5 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `latitud…
|
||||||
6 | latitude: float
|
6 | latitude: float
|
||||||
| ^^^^^^^^ Field `latitude` defined here without a default value
|
| ^^^^^^^^^^^^^^^ Field `latitude` defined here without a default value
|
||||||
7 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longitu…
|
7 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longitu…
|
||||||
8 | longitude: float
|
8 | longitude: float
|
||||||
|
|
|
|
||||||
|
@ -66,7 +66,7 @@ error[invalid-named-tuple]: NamedTuple field without default value cannot follow
|
||||||
6 | latitude: float
|
6 | latitude: float
|
||||||
7 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longit…
|
7 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longit…
|
||||||
8 | longitude: float
|
8 | longitude: float
|
||||||
| ^^^^^^^^^ Field `longitude` defined here without a default value
|
| ^^^^^^^^^^^^^^^^ Field `longitude` defined here without a default value
|
||||||
9 |
|
9 |
|
||||||
10 | class StrangeLocation(NamedTuple):
|
10 | class StrangeLocation(NamedTuple):
|
||||||
|
|
|
|
||||||
|
@ -83,7 +83,7 @@ error[invalid-named-tuple]: NamedTuple field without default value cannot follow
|
||||||
14 | altitude: float = 0.0
|
14 | altitude: float = 0.0
|
||||||
| --------------------- Earlier field `altitude` defined here with a default value
|
| --------------------- Earlier field `altitude` defined here with a default value
|
||||||
15 | latitude: float # error: [invalid-named-tuple]
|
15 | latitude: float # error: [invalid-named-tuple]
|
||||||
| ^^^^^^^^ Field `latitude` defined here without a default value
|
| ^^^^^^^^^^^^^^^ Field `latitude` defined here without a default value
|
||||||
16 | longitude: float # error: [invalid-named-tuple]
|
16 | longitude: float # error: [invalid-named-tuple]
|
||||||
|
|
|
|
||||||
info: rule `invalid-named-tuple` is enabled by default
|
info: rule `invalid-named-tuple` is enabled by default
|
||||||
|
@ -100,7 +100,7 @@ error[invalid-named-tuple]: NamedTuple field without default value cannot follow
|
||||||
| --------------------- Earlier field `altitude` defined here with a default value
|
| --------------------- Earlier field `altitude` defined here with a default value
|
||||||
15 | latitude: float # error: [invalid-named-tuple]
|
15 | latitude: float # error: [invalid-named-tuple]
|
||||||
16 | longitude: float # error: [invalid-named-tuple]
|
16 | longitude: float # error: [invalid-named-tuple]
|
||||||
| ^^^^^^^^^ Field `longitude` defined here without a default value
|
| ^^^^^^^^^^^^^^^^ Field `longitude` defined here without a default value
|
||||||
17 |
|
17 |
|
||||||
18 | class VeryStrangeLocation(NamedTuple):
|
18 | class VeryStrangeLocation(NamedTuple):
|
||||||
|
|
|
|
||||||
|
@ -115,7 +115,7 @@ error[invalid-named-tuple]: NamedTuple field without default value cannot follow
|
||||||
18 | class VeryStrangeLocation(NamedTuple):
|
18 | class VeryStrangeLocation(NamedTuple):
|
||||||
19 | altitude: float = 0.0
|
19 | altitude: float = 0.0
|
||||||
20 | latitude: float # error: [invalid-named-tuple]
|
20 | latitude: float # error: [invalid-named-tuple]
|
||||||
| ^^^^^^^^ Field `latitude` defined here without a default value
|
| ^^^^^^^^^^^^^^^ Field `latitude` defined here without a default value
|
||||||
21 | longitude: float # error: [invalid-named-tuple]
|
21 | longitude: float # error: [invalid-named-tuple]
|
||||||
22 | altitude: float = 0.0
|
22 | altitude: float = 0.0
|
||||||
|
|
|
|
||||||
|
@ -131,7 +131,7 @@ error[invalid-named-tuple]: NamedTuple field without default value cannot follow
|
||||||
19 | altitude: float = 0.0
|
19 | altitude: float = 0.0
|
||||||
20 | latitude: float # error: [invalid-named-tuple]
|
20 | latitude: float # error: [invalid-named-tuple]
|
||||||
21 | longitude: float # error: [invalid-named-tuple]
|
21 | longitude: float # error: [invalid-named-tuple]
|
||||||
| ^^^^^^^^^ Field `longitude` defined here without a default value
|
| ^^^^^^^^^^^^^^^^ Field `longitude` defined here without a default value
|
||||||
22 | altitude: float = 0.0
|
22 | altitude: float = 0.0
|
||||||
|
|
|
|
||||||
info: Earlier field `altitude` was defined with a default value
|
info: Earlier field `altitude` was defined with a default value
|
||||||
|
|
|
@ -769,13 +769,14 @@ impl DefinitionKind<'_> {
|
||||||
target_range.cover(value_range)
|
target_range.cover(value_range)
|
||||||
}
|
}
|
||||||
DefinitionKind::AnnotatedAssignment(assign) => {
|
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 {
|
if let Some(ref value) = assign.value {
|
||||||
let value_range = value.node(module).range();
|
full_range = full_range.cover(value.node(module).range());
|
||||||
target_range.cover(value_range)
|
|
||||||
} else {
|
|
||||||
target_range
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
full_range
|
||||||
}
|
}
|
||||||
DefinitionKind::AugmentedAssignment(aug_assign) => aug_assign.node(module).range(),
|
DefinitionKind::AugmentedAssignment(aug_assign) => aug_assign.node(module).range(),
|
||||||
DefinitionKind::For(for_stmt) => for_stmt.target.node(module).range(),
|
DefinitionKind::For(for_stmt) => for_stmt.target.node(module).range(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue