conestack / node

Other
24 stars 23 forks source link

Document the truth value testing of nodes #4

Closed attilaolah closed 12 years ago

attilaolah commented 13 years ago

Nodes do not provide a __nonzero__ method. Therefore, according to standard truth value testing, python will fall back to the __len__ method.

That implies that all leaf nodes are falsy, and all non-leaf nodes are truthy. While this is not a big problem, I think it deserves a sentence in the documentation.

Code that looks like this:

return self.root['users']['chaoflow'] or None

will return None, if the chaoflow user has no child nodes, which is usually not what I want.

rnixx commented 13 years ago

oh, how bad, are you willing to add nonzero?

attilaolah commented 13 years ago

Sure, I'll add it today, along with some tests.