Skip to content
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

split before binary operators #266

Open
anntzer opened this issue Jun 3, 2016 · 6 comments
Open

split before binary operators #266

anntzer opened this issue Jun 3, 2016 · 6 comments

Comments

@anntzer
Copy link

anntzer commented Jun 3, 2016

PEP8 recently switched to recommending splitting lines before binary ops rather than after (https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator). There are some specialized knobs available (SPLIT_BEFORE_BITWISE_OPERATOR, SPLIT_BEFORE_LOGICAL_OPERATOR), but a general SPLIT_BEFORE_BINARY_OPERATOR would be simpler to work with.

@bwendling
Copy link
Member

Things get a bit difficult when multiple knobs address the same thing. For example, if SPLIT_BEFORE_BINARY_OPERATOR is True, but SPLIT_BEFORE_BITWISE_OPERATOR is False, what would the outcome be? We could of course specify the specific effect it will have, but then for someone to change the default behavior, they'll have to mess with the other knobs.

So I think that there should be an "all or nothing" knob. Either we have the current two knobs or we have one knob that effects both bitwise and logical operators.

@w0rp
Copy link

w0rp commented Sep 3, 2016

@gwelymernans You could have yapf exit with an error if two conflicting options are set, and explain why.

I would to see an option like this. I have actually been formatting code this way for a long time, for the reasons Knuth mentions. I am glad PEP8 now agrees with me.

@brendanator
Copy link

Whether or not SPLIT_BEFORE_BINARY_OPERATOR is implemented, SPLIT_BEFORE_ARITHMETIC_OPERATOR is probably needed

@alok
Copy link

alok commented May 16, 2018

@gwelymernans Any chance of implementing split before arithmetic operators? If not, I'd be happy to take a crack at it. Which files contain the necessary logic?

@bwendling
Copy link
Member

Hi @alok, I've been swamped at work, so I haven't been able to focus on YAPF in a while. If you'd like to take a crack at it, I would appreciate it.

A lot of the formatting decisions are made in format_decision_state.py. The split_penalty.py file is also a good candidate, as it increases split penalties for different decisions.

@alok
Copy link

alok commented May 16, 2018

@gwelymernans I think I'd just model it based off of the split rule for bitwise operators, though I wonder if the fact that both + and - can be used as unary operators complicates things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants