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@gmail.com>
On 3 December 2013 04:42, Andrew Barnert <abarnert@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@gmail.com   |   Brisbane, Australia