-
Notifications
You must be signed in to change notification settings - Fork 755
The preferred place to break around a binary operator is after the operator, not before it #197
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
Comments
You'd like a new error then for when someone does something like: a = ('abcdefghijk'
+ 'lmnop') Instead of a = ('abcdefghijk' +
'lmnop') Correct? |
Correct. |
+1 |
Closed with Pull #305 . Thanks for the report! |
In new version of pep8 (1.6.2) added W503 to error. See PyCQA/pycodestyle#197
In new version of pep8 (1.6.2) raise W503 as error. See PyCQA/pycodestyle#197
W503 line break before binary operator Ref: PyCQA/pycodestyle#197
W503 line break before binary operator Ref: PyCQA/pycodestyle#197
I think this is a misreading of PEP8. The PEP allows both, but weakly recommends the opposite behaviour, suggesting Knuth's style of breaking before the operator for new code. From the PEP: # No: operators sit far away from their operands
income = (gross_wages +
taxable_interest +
(dividends - qualified_dividends) -
ira_deduction -
student_loan_interest)
# Yes: easy to match operators with operands
income = (gross_wages
+ taxable_interest
+ (dividends - qualified_dividends)
- ira_deduction
- student_loan_interest) https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator I can disable this locally for myself, but I don't think this one should be turned on by default. |
Sorry for commenting on a very old issue. Looks like PEP8 has have been updated, there was more discussion about this in #498. |
@larsyencken -- No worries! That's one of the difficulties of this tool, it's trying to hit a moving target, as the actual PEP is updated from time to time. |
- Also the W503 warning that need to be manually added - See: PyCQA/pycodestyle#197
I can't get W504 passing after this fix and recent pycodestyle release. This isn't passing:
Neither is this:
Is there possibly a bug in the latest pycodestyle release, or can someone tell me what I am doing wrong, in the mean time I'm having to disable W504 as this is driving me pretty crazy :) |
@robvdl "recent pycodestyle releases" is unfortunately vague. Can you please list which versions you've tried and your configuration? |
To be clear, W503 and W504 which control the behaviour here are both disabled by default in 2.4.0, so it's unclear how you're encountering W504: Line 84 in 0364618
|
This one bit me too today.
Version info:
Could it be that the |
Yes, that is precisely what it does and is also mentioned in the docs. |
It could be possible I was getting W504 after a pycodestyle upgrade because I already had some ignores defined in setup.cfg that I was still trying to resolve after taking over a codebase. Is it possible that once you define ignores in setup.cfg the defaults no longer apply? and therefore get replaced by my ignore list defined in setup.cfg edit: I see I am basically asking the same question as @Mausy5043 I was observing this too. |
Yes, once you define a custom ignore, that overrides the default ignore list. If you wanted to also ignore those, you would need to manually specify them in addition to what you wanted to ignore. |
ignore W504[1]. tbh, not what i prefer. [1] PyCQA/pycodestyle#197
copied from me/gitmaint/.flake8: commit 3b44b36561358ea701c74cf83543b95746ef54ca Author: Open Close <[email protected]> Date: Sat Nov 24 01:46:59 2018 +0900 Fix .flake8 flake8 seems to have changed. They have not been causing Errors, though should have. Selecting W503 is a personal choice (not clear cut in upstream). PyCQA/pycodestyle#197
copied from me/gitmaint/.flake8: commit 3b44b36561358ea701c74cf83543b95746ef54ca Author: Open Close <[email protected]> Date: Sat Nov 24 01:46:59 2018 +0900 Fix .flake8 flake8 seems to have changed. They have not been causing Errors, though should have. Selecting W503 is a personal choice (not clear cut in upstream). PyCQA/pycodestyle#197
copied from me/gitmaint/.flake8: commit 3b44b36561358ea701c74cf83543b95746ef54ca Author: Open Close <[email protected]> Date: Sat Nov 24 01:46:59 2018 +0900 Fix .flake8 flake8 seems to have changed. They have not been causing Errors, though should have. Selecting W503 is a personal choice (not clear cut in upstream). PyCQA/pycodestyle#197
Pep8 recommends to break a long line after a binary operator.
This library doesn't catch when we break before the operator.
The text was updated successfully, but these errors were encountered: