Raymond declared:
----------------
> Let's be clear. These are duck-typed methods. A type check is inappropriate.
> Anything with o.items() is allowed regardless of type.
Wikipedia explains (http://en.wikipedia.org/wiki/Duck_typing):
-------------------------------------------------------------
> In computer programming with object-oriented programming languages, duck typing
> is an alternative to typing. In duck typing, an object's suitability for some
> purpose is determined by the presence of certain methods and properties [...]
I did use an actual 'type' check in one of my exmaples, and that was wrong.
It is possible to do a "duck-type check" with a `hasattr(other, 'items')`.
I don't use Counter myself -- I'll try and find some real-world examples. |