| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
|
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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
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).
Sorry, something went wrong.
Thanks!
I'd be happy to create a follow up PR or should i open issue and then link pr for this |
Sorry, something went wrong.
And Mathematica.
Yes, please open a separate issue. |
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you!
Sorry, something went wrong.
…e-146495.wWRRvx.rst Co-authored-by: sobolevn <mail@sobolevn.me>
Up to you. You can also include them in this PR. |
Sorry, something went wrong.
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. |
Sorry, something went wrong.
should we fall back to generic error message if we have gap between them ? |
Sorry, something went wrong.
Yes, I think so. |
Sorry, something went wrong.
|
with this patch aniket@DESKTOP-074O80J:/mnt/d/cpython/cpython$ git diff Grammar/python.gram
diff --git a/Grammar/python.gram b/Grammar/python.gram
index c45e2f3a28..823af82397 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -1642,7 +1642,19 @@ invalid_type_params:
"Type parameter list cannot be empty")}
invalid_bitwise_and:
- | a=bitwise_and b='&' c='&' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?") }
+ | a=bitwise_and b='&' c='&' {
+ (b->end_lineno == c->lineno)
+ ? ((b->end_col_offset == c->col_offset)
+ ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?")
+ : NULL)
+ : NULL
+ }
invalid_bitwise_or:
- | a=bitwise_or b='|' c='|' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'or' or '|' instead of '||'?") }
+ | a=bitwise_or b='|' c='|' {
+ (b->end_lineno == c->lineno)
+ ? ((b->end_col_offset == c->col_offset)
+ ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'or' or '|' instead of '||'?")
+ : NULL)
+ : NULL
+ }
output : aniket@DESKTOP-074O80J:/mnt/d/cpython/cpython$ ./python.exe -c "1 && 2"
File "<string>", line 1
1 && 2
^^
SyntaxError: invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?
aniket@DESKTOP-074O80J:/mnt/d/cpython/cpython$ ./python.exe -c "1 & & 2"
File "<string>", line 1
1 & & 2
^
SyntaxError: invalid syntax
aniket@DESKTOP-074O80J:/mnt/d/cpython/cpython$ ./python.exe -c "1 || 2"
File "<string>", line 1
1 || 2
^^
SyntaxError: invalid syntax. Maybe you meant 'or' or '|' instead of '||'?
aniket@DESKTOP-074O80J:/mnt/d/cpython/cpython$ ./python.exe -c "1 | | 2"
File "<string>", line 1
1 | | 2
^
SyntaxError: invalid syntax
previously i tried something like this but it was throwing warning during compiling invalid_bitwise_and:
| a=bitwise_and b='&' c='&' {
(b->end_lineno == c->lineno && b->end_col_offset == c->col_offset)
? RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?")
: NULL
}
these were the warning :-- lude -DPy_BUILD_CORE -o Parser/parser.o Parser/parser.c
Parser/parser.c: In function ‘invalid_bitwise_and_rule’:
Parser/parser.c:28511:77: warning: comparison between pointer and integer
28511 | _res = ( b -> end_lineno == c -> lineno & & b -> end_col_offset == c -> col_offset ) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE ( b , c , "invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?" ) : NULL;
| ^~
Parser/parser.c:28511:38: warning: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]
28511 | _res = ( b -> end_lineno == c -> lineno & & b -> end_col_offset == c -> col_offset ) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE ( b , c , "invalid syntax. Maybe you meant 'and' or '&' instead of '&&'?" ) : NULL;
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
Parser/parser.c: In function ‘invalid_bitwise_or_rule’:
Parser/parser.c:28560:77: warning: comparison between pointer and integer
28560 | _res = ( b -> end_lineno == c -> lineno & & b -> end_col_offset == c -> col_offset ) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE ( b , c , "invalid syntax. Maybe you meant 'or' or '|' instead of '||'?" ) : NULL;
| ^~
Parser/parser.c:28560:38: warning: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]
28560 | _res = ( b -> end_lineno == c -> lineno & & b -> end_col_offset == c -> col_offset ) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE ( b , c , "invalid syntax. Maybe you meant 'or' or '|' instead of '||'?" ) : NULL;
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
|
Sorry, something went wrong.
Yes, like that. Though, I think it could be factored to a helper function.
You should take into account operator precedence rules in C. |
Sorry, something went wrong.
|
The code was correct, but errorprone, thus the compiler warning. Simply add parentheses: ((b->end_lineno == c->lineno) && (b->end_col_offset == c->col_offset)). |
Sorry, something went wrong.
|
Hmm, it seems there is a bug in the python.gram parser or the Parser/parser.c generator which parses && in C code as two tokens & and & and then inserts a space between them. |
Sorry, something went wrong.
|
Anyway, if you add a helper that tests this condition in Parser/pegen.h, you can simply use it in python.gram. |
Sorry, something went wrong.
|
In my opinion && and & & are both incorrect, the error message is good enough. |
Sorry, something went wrong.
+1 make sense
should we take care of this in follow up |
Sorry, something went wrong.
|
Also please let me know your thoughts on this as well #151375 |
Sorry, something went wrong.
I typed '& &', not '&&'. And maybe actually meant something like '& 7' (a typo). |
Sorry, something went wrong.
There was a problem hiding this comment.
Add tests with space between operators, e.g. a & & b.
Sorry, something went wrong.
There was a problem hiding this comment.
This is actually a regexp. So escape ? (in other test too).
Sorry, something went wrong.
|
gentle ping! should we move this forward so that we can also address the follow up PR. Thanks! |
Sorry, something went wrong.
|
@pablogsal, could you review the current version? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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 !