[Python-ideas] collections.abc.Stream

Michael Selik michael.selik at gmail.com
Sat Jun 18 10:29:37 EDT 2016


On Sat, Jun 18, 2016 at 7:47 AM Bar Harel <bzvi7919 at gmail.com> wrote:

> This is the fundamental idea behind duck typing - you only need to
>> implement the methods needed by the code you're calling.
>>
>
> But then again, the problem is that you don't know what methods are needed
> by the code.
>

Pass a stub object into the function and it will raise AttributeError or
TypeError. That's the best way to learn about what interface is necessary.


> I believe trial & error, and looking through the source code is a poor
> solution compared to the precise documentation of the required methods.
>

Documentation can go stale very easily. An AttributeError never lies; it
tells you exactly which method you need to implement.

Take a look at IOBase. There's a whole lot going on there that's
unnecessary for a function that just expects a ``read`` method.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160618/4c7321c6/attachment.html>


More information about the Python-ideas mailing list