gh-146495: Improve SyntaxError message for && and || operators#150906
gh-146495: Improve SyntaxError message for && and || operators#150906Aniketsy wants to merge 3 commits into
SyntaxError message for && and || operators#150906Conversation
| "invalid syntax. Maybe you meant 'and' or '&' instead of '&&'"); | ||
| return; | ||
| } | ||
| if (last_token->type == VBAR && p->tokens[p->fill - 2]->type == VBAR) { |
| def test_double_pipe(self): | ||
| self._check_error( | ||
| "a || b", | ||
| "Maybe you meant 'or' or '|' instead of '||'", |
There was a problem hiding this comment.
Can you please also assert the error location, it should be the second | or & char.
There was a problem hiding this comment.
thanks for the review, i've updated with error location, please let me know if we need any further improvements
| RAISE_SYNTAX_ERROR_KNOWN_RANGE(p->tokens[p->fill - 2], last_token, | ||
| "invalid syntax. Maybe you meant 'or' or '|' instead of '||'"); | ||
| return; | ||
| } |
There was a problem hiding this comment.
This is not a good approach for this: _Pypegen_set_syntax_error is a generic functions to set a syntax erroor it should absolutely not know about generic error conditions that are derived from thr Grammar semantics, only the tokenizer middle language (that's why out checks for INDENT/DEDENT). The correct way to raise custom syntax errors is custom grammar rules that trigger on the second pass via invalid_ rules
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |

fixes #146495
As there was not any pr for this for long time, so i thought to give a try for this as @skirpichev have shared the patch towards fix. Hoping it does not create much pain to review for members. Thank you !
&&and||#146495