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

Guido van Rossum guido at python.org
Mon Dec 2 16:59:25 CET 2013


Sounds like a cute thing to post on PyPI and see how popular it becomes.
You have until the 3.5 release cycle starts to gather votes and
improvements. There are lots of edge cases I could see going wrong, so I'm
kind of skeptical of having this in the stdlib without strong caveats about
its usefulness. Maybe it could go in the inspect module, which is
traditionally full of heuristics.


On Mon, Dec 2, 2013 at 7:55 AM, Gregory Salvan <apieum at gmail.com> wrote:

> Hi,
> I've made a try of a function that check object/class members for duck
> typing.
>
> For now I've basically called it isducktype(X, A)
> it returns true if:
> - X has all attributes of A
> - X methods have same number of arguments than corresponding A methods
>
> or if A.__ducktypecheck__(X) returns True
>
> Behaviour looks like isinstance and issubclass (support tuples...).
>
> To test it:
> The patch with example is here:
> https://gist.github.com/apieum/7751279
>
> Or you can use my branch here:
> https://bitbucket.org/gsalvan/cpython/commits/branch/default
>
>
> Any opinion about a feature like this ?
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
>


-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131202/8a0f8982/attachment.html>


More information about the Python-ideas mailing list