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

Option for not adding spaces around binary operators #155

Open
sglyon opened this issue Jun 8, 2015 · 5 comments
Open

Option for not adding spaces around binary operators #155

sglyon opened this issue Jun 8, 2015 · 5 comments

Comments

@sglyon
Copy link

sglyon commented Jun 8, 2015

Sometimes in the scientific code I write it helps readability if I can group chunks of an equation together by not adding spaces around all binary operators (*, +, -, \, **).

Is there a way to tell yapf not to add spaces around these operators?

@bwendling
Copy link
Member

There's no option for doing that at the moment. It might be relatively easy to add it though.

@hayd
Copy link
Contributor

hayd commented Oct 16, 2015

Usually you don't want spaces around **, but most likely the heuristic would only remove spaces if there were multiple operators in the same line - to make precedence clearer.

a*b
a * b

a * b + c
a*b + c

a ** b + c
a**b + c

potentially you even want parenthesis to make it clearer still:

a * b + a * b * c + d ** a * b
a*b + a*b*c + (d**a * b)

See pep8 suggestions about this:

Yes:

i = i + 1
submitted += 1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)

No:

i=i+1
submitted +=1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)

The latter is a bit of a strange one IMO.

@bwendling
Copy link
Member

Ah yes, one of the PEPs that I don't like. :-) I can work on it soon-ish.

@edwinksl
Copy link

edwinksl commented Jun 4, 2017

Any updates on this besides using #yapf: disable?

@bwendling
Copy link
Member

I haven't had too much time to work on it lately. disable may be the best bet in such cases. (Or a PR if you're inclined.)

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

4 participants