Skip to content

Update Indexer to use new tokens to compute the ranges #7290

@dhruvmanila

Description

@dhruvmanila

The Indexer needs to be updated to use the new f-string tokens to compute the following ranges:

  1. F-string ranges
  2. Triple-quoted string ranges

The f-string ranges (1) can be computed using the start range of a FStringStart token to the end range of a FStringEnd token. Here, a stack would probably be required as f-strings can be nested and we need to pick up the correct start value for the current end value. It would be similar to computing the ranges of parentheses pair in (foo, (bar, baz), another, (start, (nested, done), nope), last).

A FStringStart/FStringEnd token consists of prefixes (f, fr, etc.) and quotes. Using this information we can detect if a f-string is tripled-quoted or not using either of the following proposed solutions:

  1. Using the Locator, we can extract out the source for the FStringStart token using the token range, extract the quotes using leading_quote and use the .text_len method to check the number of quotes.
  2. We can store additional information in the FStringStart token itself in the form of bitflags or boolean values similar to FStringMiddle. This can then be used to check if it's a tripled-quoted f-string or not.

Metadata

Metadata

Assignees

Labels

coreRelated to core functionalitypython312Related to Python 3.12

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions