-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-43797: Improve syntax error for invalid comparisons #25317
Conversation
a36abe8
to
8d7971c
Compare
527808d
to
e23664c
Compare
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.
This inspired me to point out a whole lotta nits with the phrasing of the errors. But basically I think this is an improvement, so if you don't feel like fixing all those, that's fine with me. (Maybe check with Serhiy again.)
Lib/test/test_generators.py
Outdated
@@ -2013,7 +2013,7 @@ def printsolution(self, x): | |||
>>> def f(): (yield bar) = y | |||
Traceback (most recent call last): | |||
... | |||
SyntaxError: cannot assign to yield expression | |||
SyntaxError: cannot assign to yield expression. Maybe you meant '==' instead of '='? |
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.
Here and elsewhere it feels jarring that the initial sentence ("cannot ...") doesn't start with a capital letter, but is followed by a period and another sentence that does.
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.
Ok, I can update the error message with a capital letter.
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.
Actually, on second thought, the capital letter technically is the "S" in SyntaxError
no?
@@ -103,7 +103,7 @@ | |||
>>> dict(a = i for i in range(10)) | |||
Traceback (most recent call last): | |||
... | |||
SyntaxError: invalid syntax | |||
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='? |
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.
I'm not sure the suggestion here is very useful. More likely some other misunderstanding or typo happened.
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.
In this particular example yes, but imagine something like all(x = y for x in elements for y in other_elements)
. As it makes more sense depending on the actual function, is going to be hard to contextualize.
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
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.
Thanks! I agree on your pushback.
@pablogsal: Please replace |
https://bugs.python.org/issue43797