mirror of https://github.com/astral-sh/ruff
[ty] Fix panic for unclosed string literal in type annotation position (#21592)
This commit is contained in:
parent
d24c891a4b
commit
aec225d825
|
|
@ -773,10 +773,14 @@ pub trait StringFlags: Copy {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The total length of the string's closer.
|
/// The total length of the string's closer.
|
||||||
/// This is always equal to `self.quote_len()`,
|
/// This is always equal to `self.quote_len()`, except when the string is unclosed,
|
||||||
/// but is provided here for symmetry with the `opener_len()` method.
|
/// in which case the length is zero.
|
||||||
fn closer_len(self) -> TextSize {
|
fn closer_len(self) -> TextSize {
|
||||||
self.quote_len()
|
if self.is_unclosed() {
|
||||||
|
TextSize::default()
|
||||||
|
} else {
|
||||||
|
self.quote_len()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any_string_flags(self) -> AnyStringFlags {
|
fn as_any_string_flags(self) -> AnyStringFlags {
|
||||||
|
|
|
||||||
|
|
@ -715,3 +715,17 @@ def _(a: int, b: str, c: int | str):
|
||||||
x9: int | str | None = f(lst(c))
|
x9: int | str | None = f(lst(c))
|
||||||
reveal_type(x9) # revealed: int | str | None
|
reveal_type(x9) # revealed: int | str | None
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Forward annotation with unclosed string literal
|
||||||
|
|
||||||
|
Regression test for [#1611](https://github.com/astral-sh/ty/issues/1611).
|
||||||
|
|
||||||
|
<!-- blacken-docs:off -->
|
||||||
|
|
||||||
|
```py
|
||||||
|
# error: [invalid-syntax]
|
||||||
|
# error: [invalid-syntax-in-forward-annotation]
|
||||||
|
a:'
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- blacken-docs:on -->
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue