gh-146495: Improve SyntaxError message for && and || operators#150906
gh-146495: Improve SyntaxError message for && and || operators#150906Aniketsy wants to merge 12 commits into
SyntaxError message for && and || operators#150906Conversation
|
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 |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. 👍
As I proposed in #151129 (comment), we can also add suggestions for <> ("not equal" in Pascal and Python 2), "=<", "=>" and "=!" (typo in "<=", ">=" and "!="), "===" ("is" in JavaScript and PHP).
Thanks!
I'd be happy to create a follow up PR or should i open issue and then link pr for this |
And Mathematica.
Yes, please open a separate issue. |
…e-146495.wWRRvx.rst Co-authored-by: sobolevn <mail@sobolevn.me>
Up to you. You can also include them in this PR. |
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
|
Sorry, this doesn't look acceptable for me: >>> 1 & & 2
File "<python-input-1>", line 1
1 & & 2
^^^
SyntaxError: invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?I think you should raise a different exception message only for cases, when '&&' or '||' could be interpreted as distinct tokens. |
should we fall back to generic error message if we have gap between them ? |
Yes, I think so. |
|
with this patch output : previously i tried something like this but it was throwing warning during compiling these were the warning :-- |
Yes, like that. Though, I think it could be factored to a helper function.
You should take into account operator precedence rules in C. |
|
The code was correct, but errorprone, thus the compiler warning. Simply add parentheses: |
|
Hmm, it seems there is a bug in the |
|
Anyway, if you add a helper that tests this condition in |
|
In my opinion |
+1 make sense
should we take care of this in follow up |
|
Also please let me know your thoughts on this as well #151375 |
I typed '& &', not '&&'. And maybe actually meant something like '& 7' (a typo). |
skirpichev
left a comment
There was a problem hiding this comment.
Add tests with space between operators, e.g. a & & b.
There was a problem hiding this comment.
This is actually a regexp. So escape ? (in other test too).

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