duck typing assert‏

Steven D'Aprano steve+comp.lang.python at
Fri Nov 9 00:40:19 CET 2012

On Thu, 08 Nov 2012 15:39:24 -0500, Terry Reedy wrote:

> UserWarning: 'bar': is not property.
>    assert looks(Foo).like(IFoo)
> Traceback (most recent call last):
>    File "", line 21, in
>      assert looks(Foo).like(IFoo)
> AssertionError
> '''
> I view this check as an error. Properties are intended to be transparent
> to the user. One use of properties is to make something that is not a
> Mallard act like a Mallard. So this check breaks duck typing.

Properties and methods do not have the same interface:  # returns a computed property  # calls a method

Since the interfaces are different, duck-typing will fail. It will 
actually fail in a potentially nasty way:

x =  # doesn't raise an exception, gives the method object
# ... much later
do_something_with(x)  # blows up potentially far, far away


More information about the Python-list mailing list