Pre/Postconditions with decorators
George Sakkis
gsakkis at rutgers.edu
Sun Jan 9 13:10:08 EST 2005
"Stephen Thorne" <stephen.thorne at gmail.com> wrote:
> Unresolved Problems:
> 1) How do you handle duck types, i.e. a method that accepts StringIO,
> cStringIO or any other object that has a .readlines(), .seek() and
> .read() method?
I think the 'proper' way of checking duck types (among other things) is by defining appropriate
protocols; check pyProtocols (http://peak.telecommunity.com/PyProtocols.html) for details.
> 2) How do you turn off the type checking for production code?
Currently I don't, but that's easy to do if desired by checking __debug__ in the decorator and
return the passed function if it is false:
def params(**checkedArgs):
if not __debug__:
return lambda function: function
# else return a typechecked proxy of function
(...)
> Otherwise I quite like it. Please publish it somewhere.
Thanks. I'll post an entry on Vaults of Parnassus as soon as I publish it.
George
More information about the Python-list
mailing list