Use if foo
or if not foo
. There isn't any need for either ==
or is
for that.
For checking against None, is None
and is not None
are recommended. This allows you to distinguish it from False (or things that evaluate to False, like ""
and []
).
Whether get_attr
should return None
would depend on the context. You might have an attribute where the value is None, and you wouldn't be able to do that. I would interpret None
as meaning "unset", and a KeyError
would mean the key does not exist in the file.