[Python-ideas] check interfaces, isducktype(X, A)

Gregory Salvan apieum at gmail.com
Wed Dec 4 06:22:06 CET 2013


Sorry Andrew, I'm not sure to understand all your point.
I don't believe it reimplements things of ABC, or I don't see what.

I agree ABC solution is the cleanest, whereas I would be able to check
functions, stay on a runtime checking and being free to define or not a
kind of protocol.

Before reading your comments on ABC, I've released the python version of
"isducktype": https://github.com/apieum/ducktype
I've modified some behaviours within your comments and made it more stable.

It would be interesting to have the version wich use ABCMeta, so I'm going
to implement it.
I've thought to name it SignedMeta, or ProtocolMeta, any opinion ?







2013/12/3 Nick Coghlan <ncoghlan at gmail.com>

> On 3 December 2013 04:42, Andrew Barnert <abarnert at yahoo.com> wrote:
> > Shouldn't this be tied to ABCs rather than redesigning and reimplementing
> > most of ABC to add a little bit on top?
>
> This seems like an apropos place for this link:
> http://docs.python.org/3/library/abc#abc.ABCMeta.__subclasshook__
>
> That's the existing "formalised ducktyping" hook, that already allows
> things like the following:
>
> >>> class MyClass:
> ...     def __len__(self):
> ...         return 0
> ...
> >>> from collections.abc import Sized
> >>> isinstance(MyClass(), Sized)
> True
> >>> issubclass(MyClass, Sized)
> True
>
> The advantage ABCs have over ducktyping alone is that subclassing and
> explicit registration allow ambiguities like the one between the
> Sequence and Mapping interfaces to be resolved (you can't always just
> ducktype those, as they have the same methods - they differ only in
> how the __*item__ methods handle slice objects).
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131204/aaf3ddb8/attachment.html>


More information about the Python-ideas mailing list