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

No warning about missing space between closing parenthesis and keyword #371

Open
dpursehouse opened this issue Jan 16, 2015 · 13 comments
Open
Assignees

Comments

@dpursehouse
Copy link
Contributor

The following code does not result in any warnings:

if a()and b():
    pass

if b()in [1, 2, 3]:
    pass

if c()or d():
    pass
@IanLee1521 IanLee1521 self-assigned this Jan 16, 2015
@methane
Copy link
Contributor

methane commented Sep 3, 2015

Missing space between keyword and opening parenthesis doesn't raise warning too.

if(1 == 0):
    pass

@OswinNathanial
Copy link

The following does not raise any warnings:

x = a-b

where as the following does:

x = a -b

x = a- b

@sigmavirus24
Copy link
Member

What versions of pep8 are all of you using?

@OswinNathanial
Copy link

The problem I mentioned exists in version 1.6.2

@jayvdb
Copy link
Member

jayvdb commented Aug 18, 2016

@OswinNathanial , pep8 is very clear about consistent spacing around operators, but is lax about one versus zero spaces.

"If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgment; however, never use more than one space, and always have the same amount of whitespace on both sides of a binary operator."

@methane, your case is not covered by the above, and I cant find anything explicitly rejecting that syntax in pep8. I've forked that off to be #570, as it is a bit of a mine field of vague and unspecified implied styles.

Regarding the original issue, pep8 guideline is very clear about spaces around in and or:

"Always surround these binary operators with a single space on either side: assignment ( = ), augmented assignment ( += , -= etc.), comparisons ( == , < , > , != , <> , <= , >= , in , not in , is , is not ), Booleans ( and , or , not ). "

And I can confirm that is not checked in the latest pycodestyle.

@asottile
Copy link
Member

#631 includes another few cases for this:

[(a,)for a in y]
from .import bar
try:
    ...
except(IOError,):
    ...

@asottile
Copy link
Member

#570 also contains some cases for this as well with if(...)

@asottile
Copy link
Member

#646 also includes some cases for in(...) and or(...)

@asottile
Copy link
Member

#650 also mentions return(...) / return[...]

@asottile
Copy link
Member

#843 points out these oddities as well (which are enough to confuse github's parser!):

0and 1
0x1or 0

@jpmckinney
Copy link

Noting that in 2.9.0, code like a, b, c = (yield) now complains about there not being a space after yield. I just removed the parentheses as they serve no purpose, but it's weird that I should have to write (yield ) if I wanted to preserve them.

@asottile
Copy link
Member

asottile commented Aug 2, 2022

@jpmckinney please open a new issue with a full code sample and output and we can fix it. there are cases iirc where yield does need parenthesizing and we should make sure those are handled properly -- a small oversight while implementing this

@jpmckinney
Copy link

Thanks, @asottile. I've opened #1090.

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

No branches or pull requests

8 participants