Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-133357: FixSyntaxError 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
sobolevn wants to merge3 commits intopython:mainfromsobolevn:issue-133357

Conversation

sobolevn
Copy link
Member

@sobolevnsobolevn commentedMay 5, 2025
edited by bedevere-appbot
Loading

I went with the simplest possible change:
Снимок экрана 2025-05-05 в 19 40 47

Now carret always points to the star itself.

Why?

  1. BecauseRAISE_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().
  2. Changingstarred_expressions also seems rather hard:
starred_expression[expr_ty]:| invalid_starred_expression_unpacking    | '*' a=expression { _PyAST_Starred(a,Load,EXTRA) }|invalid_starred_expression

So, I decided to keep it simple.

@pablogsal
Copy link
Member

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

@lysnikolaou
Copy link
Member

Agreed on the point about complexity. Is this an improvement over the status quo though?

@sobolevn
Copy link
MemberAuthor

Is this an improvement over the status quo though?

Yes, I think it is. Compare my current branch:

Снимок экрана 2025-05-05 в 19 40 47

Withmain:

Снимок экрана 2025-05-05 в 21 12 42

Currently, we point at different chars in seemingly random places::,]
When the problem always starts with*

@pablogsal
Copy link
Member

@lysnikolaou are you ok if we go with this?

Copy link
Contributor

@StanFromIrelandStanFromIreland left a 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?

@sobolevn
Copy link
MemberAuthor

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.

@pablogsal
Copy link
Member

We normally either add them in test exceptions or test syntax

@StanFromIreland
Copy link
Contributor

I proposed a test in a PR against your branch.

@lysnikolaou
Copy link
Member

lysnikolaou commentedMay 5, 2025
edited
Loading

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, ifA is anndarray, it's the] or the: that make this invalid syntax since the following would be a valid index:

A[*(1,)]

@sobolevn
Copy link
MemberAuthor

@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?

@lysnikolaou
Copy link
Member

@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?

@vitaldmit
Copy link
Contributor

vitaldmit commentedMay 9, 2025
edited
Loading

Maybe just keep this as is?

@lysnikolaou I think it's better just keep this as is. It's cleaner and clearer. There is no need to make tildes and complicate the code.

@sobolevn
Copy link
MemberAuthor

Ok, lets keep it as is :)

@StanFromIreland
Copy link
Contributor

Maybe a test and link to this discussion would be good to prevent this changing yet again?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@pablogsalpablogsalpablogsal approved these changes

@lysnikolaoulysnikolaouAwaiting requested review from lysnikolaoulysnikolaou is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@sobolevn@pablogsal@lysnikolaou@StanFromIreland@vitaldmit

[8]ページ先頭

©2009-2025 Movatter.jp