Skip to content

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

Closed
come-maiz opened this issue May 14, 2013 · 14 comments
Labels

Comments

@come-maiz
Copy link

Pep8 recommends to break a long line after a binary operator.
This library doesn't catch when we break before the operator.

@sigmavirus24
Copy link
Member

You'd like a new error then for when someone does something like:

a = ('abcdefghijk'
     + 'lmnop')

Instead of

a = ('abcdefghijk' +
     'lmnop')

Correct?

@come-maiz
Copy link
Author

Correct.

@glarrain
Copy link

glarrain commented Jun 8, 2013

+1

@IanLee1521
Copy link
Member

Closed with Pull #305 . Thanks for the report!

ar4s pushed a commit to ar4s/ralph_assets that referenced this issue Feb 16, 2015
In new version of pep8 (1.6.2) added W503 to error. See
PyCQA/pycodestyle#197
ar4s pushed a commit to ar4s/ralph_assets that referenced this issue Feb 16, 2015
In new version of pep8 (1.6.2) raise W503 as error. See
PyCQA/pycodestyle#197
tvoinarovskyi added a commit to TarasLevelUp/asynqp that referenced this issue Mar 8, 2016
W503 line break before binary operator

Ref: PyCQA/pycodestyle#197
tvoinarovskyi added a commit to TarasLevelUp/asynqp that referenced this issue Mar 8, 2016
W503 line break before binary operator

Ref: PyCQA/pycodestyle#197
@larsyencken
Copy link

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.

@larsyencken
Copy link

Sorry for commenting on a very old issue. Looks like PEP8 has have been updated, there was more discussion about this in #498.

@IanLee1521
Copy link
Member

@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.

@robvdl
Copy link

robvdl commented May 31, 2018

I can't get W504 passing after this fix and recent pycodestyle release.

This isn't passing:

expected_url = (CONFIG['client']['url_prefix']
                + CONFIG['client']['url_path']
                + CONFIG['client']['create_parcel'].format(service_code='runjump'))

Neither is this:

expected_url = (CONFIG['client']['url_prefix'] +
                CONFIG['client']['url_path'] +
                CONFIG['client']['create_parcel'].format(service_code='runjump'))

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 :)

@sigmavirus24
Copy link
Member

@robvdl "recent pycodestyle releases" is unfortunately vague. Can you please list which versions you've tried and your configuration?

@sigmavirus24
Copy link
Member

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:

DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503,W504'

@Mausy5043
Copy link

Mausy5043 commented Jun 17, 2018

This one bit me too today.

$ pycodestyle --ignore=E111,E221,E114,E501,C901 .
./tests/testd.py:45:24: W503 line break before binary operator
./tests/testd.py:46:24: W503 line break before binary operator
ERROR: Job failed: exit code 1

Version info:

Collecting pycodestyle
  Downloading https://files.pythonhosted.org/packages/e5/c6/blablabla/pycodestyle-2.4.0-py2.py3-none-any.whl (62kB)

Could it be that the --ignore overrides the internal defaults instead of adding to them?

@FichteFoll
Copy link
Contributor

Yes, that is precisely what it does and is also mentioned in the docs.

@robvdl
Copy link

robvdl commented Jun 17, 2018

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.

@IanLee1521
Copy link
Member

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.

su27 added a commit to su27/vitamine that referenced this issue Oct 31, 2018
chungg pushed a commit to chungg/python-gnocchiclient that referenced this issue Nov 8, 2018
ignore W504[1]. tbh, not what i prefer.

[1] PyCQA/pycodestyle#197
openandclose added a commit to openandclose/configfetch that referenced this issue Nov 24, 2018
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
openandclose added a commit to openandclose/tosixinch that referenced this issue Nov 24, 2018
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
openandclose added a commit to openandclose/zconfigparser that referenced this issue Feb 4, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants