Hacker News new | ask | show | jobs
by anitil 762 days ago
In your first example I think most people would skip the 'is not None' as None is already falsy and drop the extra braces.

I find it visually clearer than the second example where the cause and effect are slightly separated, but I do agree there's an element of cleverness to it.

2 comments

But that would be a mistake if you need the branch to run for other falsely values like 0 or the empty string.
In this imaginary example, yes, a False is likely to cause the same issues that None would. But as a sibling comment mentions, it’s not always desirable to drop the explicitness for syntactic sugar.