Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to parse type aliases in same line body #8900

Closed
MichaReiser opened this issue Nov 29, 2023 · 0 comments · Fixed by #8916
Closed

Fails to parse type aliases in same line body #8900

MichaReiser opened this issue Nov 29, 2023 · 0 comments · Fixed by #8916
Assignees
Labels
bug Something isn't working parser Related to the parser

Comments

@MichaReiser
Copy link
Member

MichaReiser commented Nov 29, 2023

Ruff fails to parse type aliases in same line bodies

class X: type InClass = int

This prevents us from importing Black's type_aliases.py test case

@MichaReiser MichaReiser changed the title Fails to parse type aliases in class inheritance clause Fails to parse type aliases in same line body Nov 29, 2023
@MichaReiser MichaReiser added bug Something isn't working parser Related to the parser labels Nov 29, 2023
@charliermarsh charliermarsh self-assigned this Nov 30, 2023
charliermarsh added a commit that referenced this issue Nov 30, 2023
<!--
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 #8900.
Closes #8899.

## Test Plan

`cargo test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser Related to the parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants