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:<br>
<br> def playWithDuck(d):<br> d.walk()<br> d.quack()<br><br>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 could write:<br>
<br> def playWithDuck(d):<br> d.quack # raises AttributeError if can't quack<br> d.walk()<br> d.quack()<br><br>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<br>
<br> def playWithDuck(d):<br> if not isinstance(d, Duck):<br> raise TypeError("need a Duck")<br> ...<br><br>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).<br>
<br>Is this the problem you are trying to solve? Or something else?<br><br>--- Bruce<br><br>