duck-type-checking?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Nov 14 19:28:04 EST 2008


On Fri, 14 Nov 2008 13:28:27 -0700, Joe Strout wrote:

> But this class wasn't really that complex; it's just that it assumed all
> the stuff it's being fed were strings (or could be treated as strings),
> and I inadvertently fed it an NLTK.Tree node instead (not realizing that
> a library method I was calling could return such a thing sometimes).

Guido has published a couple of metaclasses to get Eiffel-style pre- and 
post-condition tests that may be useful for you:

http://www.python.org/doc/essays/metaclasses/

If you're interested in reading more about metaclasses, this is more 
current:

http://www.python.org/download/releases/2.2.3/descrintro/


By the way, even Guido himself isn't immune to the tendency among Python 
users to flame at anyone suggesting change to Python's model:

http://www.artima.com/weblogs/viewpost.jsp?thread=87182

(And that's a good thing. It would be really bad if the Python community 
were slavishly and mindlessly Guido-fanboys as we're sometimes accused of 
being.)



-- 
Steven



More information about the Python-list mailing list