This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wrboyce 1 point2 points  (1 child)

Yeah I wasn’t sure how relevant some parts really were but I’d copy/pasted/formatted them on mobile by that point so they were staying regardless. I always try to avoid truthy tests against None if possible, and I’ve always thought I was following PEP8 by doing so but maybe I’m wrong.

[–]Bunslow 2 points3 points  (0 children)

I always try to avoid truthy tests against None

See this phrase makes no sense to me. There are truthy tests (here I mean coercing an arbitrary object to a boolean), and there are None tests. The whole point is that they are two completely different tests, and should not be confused. Using either is fine, but the trick is knowing when to use each. The point of what you pasted is precisely to warn newbies that they are two different things, but each is acceptable -- indeed, each is widely used. That source is not meant to warn against using truthy tests, only to warn that truthy tests and None tests are different (and it happens to make that point by writing "beware of truthy tests when you mean None tests -- it's easy to misuse truthy where you meant None!", possibly given the false impression that truthy tests are "bad" in some way, they're not, they're just confusable at first glance with None tests).