epiphany

Roy Smith roy at panix.com
Wed Apr 24 19:50:33 EDT 2013


I discovered something really neat today.

We've got a system with a bunch of rules.  Each rule is a method which 
returns True or False.  At some point, we need to know if all the rules 
are True.  Complicating things, not all the rules are implemented.  
Those that are not implemented raise NotImplementedError.

We used to have some ugly logic which kept track of which rules were 
active and only evaluated those.

So, here's the neat thing.  It turns out that bool(NotImplemented) 
returns True.  By changing the unimplemented rules from raising 
NotImplementedError to returning NotImplemented, the whole thing becomes:

    return all(r() for r in rules)



More information about the Python-list mailing list