-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
++ does not throw a SyntaxError #83697
Comments
Python 3.9.0a0 (heads/master-dirty:d8ca2354ed, Oct 30 2019, 20:25:01)
[GCC 9.2.1 20190909] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 ++ 2
3 This is probably because the interpreter reads: 1 + +2
|
This is not a bug, as you have pointed out yourself you are using a binary plus and a unary plus operator in the same expression. This has been part of Python since version 1, and with operator overloading
The first expression is not "unreadable". The fact that you were able to read it and diagnose it yourself as a binary operator followed by a unary operator proves that you can, in fact, read it. And it probably wasn't that hard to understand. (It wasn't for me.) It would be easier to read if you used spaces around the binary plus and no space between the unary plus and its operand, but it can still be read and understood even with the unusual spacing. |
This is not a "meaning". >>> 1++
File "<stdin>", line 1
1++
^
SyntaxError: invalid syntax
The fact I understood it it's because I'm a programmer with more than 10 years of experience, mainly in Python. And I discovered this defect by acccident, because I wanted to write So, in my "humble" opinion, it's *highly* unreadable and surprising. |
Marco, this is no more of a defect than
As a programmer with more than 10 years experience, you should know that |
Indeed the problem is that no error or warning is raised if two operators are consecutive, without a space between. All the cases you listed are terribly unreadable and hardly intelligible. Anyway I do not agree
But you should know that in a lot of other popular languages, This is completely confusing and messy. Frankly, I'm not a PEP-8 orthodox at all. I think that you can write But you should not be allowed to write |
FWIW, this is the sort of thing that is usually best suited to be reported by linters, not the Python runtime. |
TL;DR: if you write something like Long version: Normally I agree, but not in this case. PEP-8 defines line guides for writing a more readable code. They are not mandatory because:
That said, none of these valid border cases can be applied to this case:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: