-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-133357: Fix SyntaxError
carret location on invalid starred exprs
#133455
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
base: main
Are you sure you want to change the base?
Conversation
Yeah I don't want to over complicate this because not only is very easy to make it slower for no real gain in most cases but the more complex the rules are the more edge cases they will have and with peg that can also affect other rules |
Agreed on the point about complexity. Is this an improvement over the status quo though? |
@lysnikolaou are you ok if we go with this? |
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.
Can we add a test that actually verifys the location to prevent a future regression?
Adding such test can be done, but is rather hard to do, since there's no infrastructure for such tests as far as I know. |
We normally either add them in test exceptions or test syntax |
I proposed a test in a PR against your branch. |
Proposed test to python#133455
I'm okay to go with this if everyone else agrees, but I'm not convinced this is clearer. The caret should point to the first character that does not adhere to our syntax and this breaks that assumption. The current caret position is not random. It actually points to the correct place. In the above examples @sobolevn showed, if A[*(1,)] |
@lysnikolaou yes, this is a good point. Maybe we can come up with a better solution? Do you have an idea about what we can do? |
Ideally we would be able to place tildes below the whole expression and a caret below the position that breaks the syntax. I don't think we have that in the parser though and the complexity would be too much. Maybe just keep this as is? |
I went with the simplest possible change:

Now carret always points to the star itself.
Why?
RAISE_SYNTAX_ERROR_KNOWN_RANGE
requires the second argument, it is rather hard to match. Because simplea='*' b=expression
does not work. Because, for example,(1:2)
is not a validexpression
it is aslice
in()
.starred_expressions
also seems rather hard:So, I decided to keep it simple.
Invalid star expression
#133357