Message230692
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. |
|
Date |
User |
Action |
Args |
2014-11-05 16:04:33 | ethan.furman | set | recipients:
+ ethan.furman, rhettinger, pitrou, r.david.murray, Jim.Jewett, Joshua.Chin |
2014-11-05 16:04:33 | ethan.furman | set | messageid: <1415203473.75.0.619690692422.issue22766@psf.upfronthosting.co.za> |
2014-11-05 16:04:33 | ethan.furman | link | issue22766 messages |
2014-11-05 16:04:33 | ethan.furman | create | |
|