[Python-ideas] [Wild Idea] Static Ducks
bruce at leapyear.org
Sun Sep 20 06:21:02 CEST 2009
I don't quite understand what you are trying to solve. Here's a related
problem: One of the issues with duck typing is that something might look
sort of like a duck but isn't really and it would be nice to make it easy to
avoid using an object in a "half-baked" manner:
if someone calls playWithDuck(dog) then the dog's going to get walked before
trying to make the dog quack fails. I'd like to be able to avoid that. I
d.quack # raises AttributeError if can't quack
but of course that doesn't check that d.quack is a function or even has the
right kind of signature. And I can write
if not isinstance(d, Duck):
raise TypeError("need a Duck")
which has it's own problems (I don't need a Duck; I just need something that
walks like a duck and quacks like a duck).
Is this the problem you are trying to solve? Or something else?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas