In particular:
>>> 0 == False
True
Which makes the idiom of testing truthiness quite annoying in parsing code such as: def is_digit_char(s):
""" Return a parsed integer from 's'."""
try:
return int(s)
except (ValueError, TypeError):
return None
Which is harmless enough except that as a predicate it sucks because parsing "0" will return False in a context where I'd rather know whether I parsed an integer or not... which leads to non-idiomatic code.This is mainly because True/False are essentially aliases for 1/0 and as such won't identify so:
>>> 0 is False
False
>>> 0 is 0
True
So it's important to remember another Tim Peters-ism: Although practicality beats purity. As read in the Zen of Python it seems he's referring to special cases which this might be.As a shameless aside, you should see what we're working on in Hy. There will likely come a point where we'll be able to do kibit-style suggestions of idiomatic transformations to your Python code.
Update: I ran into this while trying to write token parsers for a parser-combinator lib in Hy.