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

Oleg Broytman phd at phdru.name
Mon Dec 2 19:10:52 CET 2013


On Mon, Dec 02, 2013 at 08:04:19PM +0200, ?????????? <elazarg at gmail.com> wrote:
> On Dec 2, 2013 6:12 PM, "Oleg Broytman" <phd at phdru.name> wrote:
> > On Mon, Dec 02, 2013 at 04:55:22PM +0100, Gregory Salvan <apieum at gmail.com>
> wrote:
> > > For now I've basically called it isducktype(X, A)
> > > it returns true if:
> > > - X has all attributes of A
> >
> >    Isn't the requirement too strong? When I need a file-like object I
> > seldom need more than .read() and .write() methods, and even of those I
> > seldom need both at once -- I usually need one or the other.
> >    Testing for strict conformance is not duck typing IMO -- it's
> > interface.
> Interfaces are for nominal languages. Technically it should be called
> x.is_structurally_subtype()

   I'm sure the terminology in Python is quite stable. There are
interfaces (there are many implementations, there is one rejected PEP
and one deferred PEP) and there is duck typing. Formalizing duck typing
is IMO constructing an interface.

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            phd at phdru.name
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-ideas mailing list