[Python-ideas] [Wild Idea] Static Ducks

Bruce Leban 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:

    def playWithDuck(d):

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:

   def playWithDuck(d):
      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

    def playWithDuck(d):
      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?

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090919/1cb60918/attachment.html>

More information about the Python-ideas mailing list