ruff/crates/ruff_python_parser/src
Charlie Marsh 20782ab02c
Support type alias statements in simple statement positions (#8916)
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

Our `SoftKeywordTokenizer` only respected soft keywords in compound
statement positions -- for example, at the start of a logical line:

```python
type X = int
```

However, type aliases can also appear in simple statement positions,
like:

```python
class Class: type X = int
```

(Note that `match` and `case` are _not_ valid keywords in such
positions.)

This PR upgrades the tokenizer to track both kinds of valid positions.

Closes https://github.com/astral-sh/ruff/issues/8900.
Closes https://github.com/astral-sh/ruff/issues/8899.

## Test Plan

`cargo test`
2023-11-30 19:15:19 +00:00
..
lexer perf(parser): use memchr for lexing comments (#8193) 2023-10-27 02:07:43 +01:00
snapshots Support type alias statements in simple statement positions (#8916) 2023-11-30 19:15:19 +00:00
context.rs Remove `Parse` trait (#6235) 2023-08-01 18:35:03 +02:00
function.rs Move `Ranged` into `ruff_text_size` (#6919) 2023-08-27 14:12:51 -04:00
invalid.rs Reject more syntactically invalid Python programs (#8524) 2023-11-07 07:16:06 -05:00
lexer.rs Lexer start of line is false only for `Mode::Expression` (#8880) 2023-11-28 20:38:25 +00:00
lib.rs Reject more syntactically invalid Python programs (#8524) 2023-11-07 07:16:06 -05:00
parser.rs Support type alias statements in simple statement positions (#8916) 2023-11-30 19:15:19 +00:00
python.lalrpop Avoid off-by-one error in with-item named expressions (#8915) 2023-11-30 00:11:04 +00:00
python.rs Avoid off-by-one error in with-item named expressions (#8915) 2023-11-30 00:11:04 +00:00
soft_keywords.rs Support type alias statements in simple statement positions (#8916) 2023-11-30 19:15:19 +00:00
string.rs remove several uses of `unsafe` (#8600) 2023-11-28 09:50:03 -05:00
token.rs Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
typing.rs Replace `.map_or(false, $closure)` with `.is_some_and(closure)` (#6244) 2023-08-01 19:29:42 +02:00