ruff/crates/ruff_python_index/src
Dhruv Manilawala 097e703071
Consider unterminated f-strings in FStringRanges (#8154)
## Summary

This PR removes the `debug_assertion` in the `Indexer` to allow
unterminated f-strings. This is mainly a fix in the development build
which now matches the release build.

The fix is simple: remove the `debug_assertion` which means that the
there could be `FStringStart` and possibly `FStringMiddle` tokens
without a corresponding f-string range in the `Indexer`. This means that
the code requesting for the f-string index need to account for the
`None` case, making the code safer.

This also updates the code which queries the `FStringRanges` to account
for the `None` case. This will happen when the `FStringStart` /
`FStringMiddle` tokens are present but the `FStringEnd` token isn't
which means that the `Indexer` won't contain the range for that
f-string.

## Test Plan

`cargo test`

Taking the following code as an example:

```python
f"{123}
```

This only emits a `FStringStart` token, but no `FStringMiddle` or
`FStringEnd` tokens.

And,

```python
f"\.png${
```

This emits a `FStringStart` and `FStringMiddle` token, but no
`FStringEnd` token.

fixes: #8065
2023-10-27 11:11:44 +00:00
..
comment_ranges.rs Use source type to determine parser mode for formatting (#8205) 2023-10-25 19:20:02 +05:30
fstring_ranges.rs Consider unterminated f-strings in FStringRanges (#8154) 2023-10-27 11:11:44 +00:00
indexer.rs Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
lib.rs Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00