mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +00:00
Avoid panics for implicitly concatenated forward references (#3700)
This commit is contained in:
parent
028329854b
commit
0f95056f13
6 changed files with 28 additions and 24 deletions
|
@ -93,15 +93,14 @@ pub fn parse_type_annotation(
|
|||
locator: &Locator,
|
||||
) -> Result<(Expr, AnnotationKind)> {
|
||||
let expression = locator.slice(range);
|
||||
let body = str::raw_contents(expression);
|
||||
if body == value {
|
||||
if str::raw_contents(expression).map_or(false, |body| body == value) {
|
||||
// The annotation is considered "simple" if and only if the raw representation (e.g.,
|
||||
// `List[int]` within "List[int]") exactly matches the parsed representation. This
|
||||
// isn't the case, e.g., for implicit concatenations, or for annotations that contain
|
||||
// escaped quotes.
|
||||
let leading_quote = str::leading_quote(expression).unwrap();
|
||||
let expr = parser::parse_expression_located(
|
||||
body,
|
||||
value,
|
||||
"<filename>",
|
||||
Location::new(
|
||||
range.location.row(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue