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

Oleg Broytman phd at phdru.name
Mon Dec 2 18:54:35 CET 2013


On Mon, Dec 02, 2013 at 05:33:10PM +0100, Gregory Salvan <apieum at gmail.com> wrote:
> @Oleg
> you can override default behaviour with __ducktypecheck__
> it's not as strict as an interface as var names can be differents and can
> have defaults.
> then instead of declaring an interface with "read" and "write", you just
> create a base class with these methods.
> 
> What solution do you suggest ?
> I've made a function that returns public members only, maybe this method
> can be exposed in the api too.
> 
> 2013/12/2 Oleg Broytman <phd at phdru.name>
> 
> > Hi!
> >
> > 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.

   I don't suggest any solution as I don't have a problem to solve with
interfaces. You are going to implement another interface checker in
addition to existing ones?
https://pypi.python.org/pypi?%3Aaction=search&term=interface&submit=search
   No objections from me.

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