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 after semicolon #8899

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

Fails to parse type aliases after semicolon #8899

MichaReiser opened this issue Nov 29, 2023 · 3 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

type One = int; type Another = str

Ruff fails to parse Another. Probably because the SoftKeywordTokenizer doesn't expect the contextual keyword type at that position.

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

@MichaReiser MichaReiser added bug Something isn't working parser Related to the parser labels Nov 29, 2023
@zanieb zanieb self-assigned this Nov 29, 2023
@zanieb
Copy link
Member

zanieb commented Nov 29, 2023

Depending on the urgency, I can try to take a look at this one.

@MichaReiser
Copy link
Member Author

I don't think its super urgent. I'm ignoring that black test for now.

@charliermarsh
Copy link
Member

(Coordinated with @zanieb, I'm gonna take this and the related parser error.)

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.

3 participants