-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Skip over trivia tokens after re-lexing #21895
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Regression test for https://github.com/astral-sh/ty/issues/1828 | ||
| (c: int = 1,f"""{d=[ | ||
| def a( | ||
| class A: | ||
| pass |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,7 +296,7 @@ Module( | |
| test: Call( | ||
| ExprCall { | ||
| node_index: NodeIndex(None), | ||
| range: 456..472, | ||
| range: 456..471, | ||
| func: Name( | ||
| ExprName { | ||
| node_index: NodeIndex(None), | ||
|
|
@@ -306,7 +306,7 @@ Module( | |
| }, | ||
| ), | ||
| arguments: Arguments { | ||
| range: 460..472, | ||
| range: 460..471, | ||
| node_index: NodeIndex(None), | ||
| args: [ | ||
| Name( | ||
|
|
@@ -581,7 +581,7 @@ Module( | |
| test: Call( | ||
| ExprCall { | ||
| node_index: NodeIndex(None), | ||
| range: 890..906, | ||
| range: 890..905, | ||
| func: Name( | ||
| ExprName { | ||
| node_index: NodeIndex(None), | ||
|
|
@@ -591,7 +591,7 @@ Module( | |
| }, | ||
| ), | ||
| arguments: Arguments { | ||
| range: 894..906, | ||
| range: 894..905, | ||
| node_index: NodeIndex(None), | ||
| args: [ | ||
| FString( | ||
|
|
@@ -832,7 +832,16 @@ Module( | |
| | | ||
| 28 | # The lexer is nested with multiple levels of parentheses | ||
| 29 | if call(foo, [a, b | ||
| | ^ Syntax Error: Expected `]`, found NonLogicalNewline | ||
| 30 | def bar(): | ||
| | ^^^ Syntax Error: Expected `]`, found `def` | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find those error messages more accurate. We only expect a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, but then the following error message points at this location "expecting |
||
| 31 | pass | ||
| | | ||
|
|
||
|
|
||
| | | ||
| 28 | # The lexer is nested with multiple levels of parentheses | ||
| 29 | if call(foo, [a, b | ||
| | ^ Syntax Error: Expected `)`, found newline | ||
| 30 | def bar(): | ||
| 31 | pass | ||
| | | ||
|
|
@@ -857,11 +866,10 @@ Module( | |
|
|
||
|
|
||
| | | ||
| 41 | # test is to make sure it emits a `NonLogicalNewline` token after `b`. | ||
| 42 | if call(foo, [a, | ||
| 43 | b | ||
| | ^ Syntax Error: Expected `]`, found NonLogicalNewline | ||
| 44 | ) | ||
| | ^ Syntax Error: Expected `]`, found `)` | ||
| 45 | def bar(): | ||
| 46 | pass | ||
| | | ||
|
|
@@ -898,7 +906,7 @@ Module( | |
| | | ||
| 49 | # F-strings uses normal list parsing, so test those as well | ||
| 50 | if call(f"hello {x | ||
| | ^ Syntax Error: Expected FStringEnd, found NonLogicalNewline | ||
| | ^ Syntax Error: Expected `)`, found newline | ||
| 51 | def bar(): | ||
| 52 | pass | ||
| | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ Module( | |
| test: Call( | ||
| ExprCall { | ||
| node_index: NodeIndex(None), | ||
| range: 3..19, | ||
| range: 3..18, | ||
| func: Name( | ||
| ExprName { | ||
| node_index: NodeIndex(None), | ||
|
|
@@ -27,7 +27,7 @@ Module( | |
| }, | ||
| ), | ||
| arguments: Arguments { | ||
| range: 7..19, | ||
| range: 7..18, | ||
| node_index: NodeIndex(None), | ||
| args: [ | ||
| Name( | ||
|
|
@@ -113,5 +113,11 @@ Module( | |
|
|
||
| | | ||
| 1 | if call(foo, [a, b def bar(): pass | ||
| | ^ Syntax Error: Expected `]`, found NonLogicalNewline | ||
| | ^^^ Syntax Error: Expected `]`, found `def` | ||
| | | ||
|
|
||
|
|
||
| | | ||
| 1 | if call(foo, [a, b def bar(): pass | ||
| | ^ Syntax Error: Expected `)`, found newline | ||
|
Comment on lines
+121
to
+122
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is bad but it's inherent to how we do recovery. The issue is that |
||
| | | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the main part of the fix based on the PR description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the other changes are mainly added assertions and some safe-guarding that we never remove any tokens that came before the non logical newline