Closed coady closed 2 years ago
I just had a quick look at PEP8, and it states:
Yes: if greeting: No: if greeting == True: Worse: if greeting is True:
On the other hand, the pep8 tool/linter has the error message E712
(http://pep8.readthedocs.org/en/latest/intro.html#error-codes) with the description:
comparison to True should be ‘if cond is True:’ or ‘if cond:’
I am not really sure what we should do in order to resolve this conflict. @acoady: What would be your resolution? Stick to the Pep8 styleguide? @adewes: Your opinion?
I'd go with PEP8 here. If greeting. It's most concise. Christoph
With which PEP8? Both sources are called Pep8. One is the official PEP8 styleguide, the other one is a tool which checks code against the PEP8 styleguide.
"Yes: if greeting"
Also, what is this supposed to mean (emphasis mine)?
The code below uses the PEP 8 preferred pattern of if cond:. This only works if the object, variable, or expression evaluates to a Boolean value of True or False.
I can't think of any expression that can't be used in a boolean context.
Pep8 does not recommend
if cond is True
; it specifically says that's even worse than== True
. Implicit booleans are recommended.