ruff/crates/ruff_python_parser/src
Shaygan Hooshyari cf4ab7cba1
Parse triple quoted string annotations as if parenthesized (#15387)
## Summary

Resolves #9467 

Parse quoted annotations as if the string content is inside parenthesis.
With this logic `x` and `y` in this example are equal:

```python
y: """
   int |
   str
"""

z: """(
    int |
    str
)
"""
```

Also this rule only applies to triple
quotes([link](https://github.com/python/typing-council/issues/9#issuecomment-1890808610)).

This PR is based on the
[comments](https://github.com/astral-sh/ruff/issues/9467#issuecomment-2579180991)
on the issue.

I did one extra change, since we don't want any indentation tokens I am
setting the `State::Other` as the initial state of the Lexer.

Remaining work:

- [x] Add a test case for red-knot.
- [x] Add more tests.

## Test Plan

Added a test which previously failed because quoted annotation contained
indentation.
Added an mdtest for red-knot.
Updated previous test.

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
2025-01-16 11:38:15 +05:30
..
lexer Mention that Cursor is based on rustc's implementation. (#12109) 2024-06-30 16:53:25 +01:00
parser Parse triple quoted string annotations as if parenthesized (#15387) 2025-01-16 11:38:15 +05:30
snapshots Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
error.rs Raise syntax error for unparenthesized generator expr in multi-argument call (#12445) 2024-07-22 14:44:20 +05:30
lexer.rs Parse triple quoted string annotations as if parenthesized (#15387) 2025-01-16 11:38:15 +05:30
lib.rs Parse triple quoted string annotations as if parenthesized (#15387) 2025-01-16 11:38:15 +05:30
string.rs Upgrade to Rust 1.81 (#13265) 2024-09-06 15:09:09 +02:00
token.rs Use CompactString for Identifier (#12101) 2024-07-01 10:06:02 +02:00
token_set.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
token_source.rs Use TokenSource to find new location for re-lexing (#12060) 2024-06-27 17:12:39 +05:30
typing.rs Parse triple quoted string annotations as if parenthesized (#15387) 2025-01-16 11:38:15 +05:30