duck typing assert

Chris Angelico rosuav at gmail.com
Fri Nov 9 07:14:49 CET 2012


On Fri, Nov 9, 2012 at 12:00 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> looks(Foo).like(IFoo), on the other hand, is crystal clear about which
> argument is which.

I'm not so sure that it is, tbh. If you read it like an English
sentence, it's clearly testing whether Foo matches the template in
IFoo, but which are you more likely to do: test one class to see if it
satisfies lots of templates, or test one template against every class
you meet? I think probably the latter is, if not more likely than the
former, at least sufficiently plausible as to create confusion. It
makes very good sense to say:

duckmatch(IFoo).compare(Foo)

ie with the arguments the other way.

ChrisA


More information about the Python-list mailing list