Re: [Python-Dev] Duck-typing self

2009-02-27 Thread Sebastian Rittau
On Wed, Feb 18, 2009 at 11:32:09PM +0100, Sebastian Rittau wrote: > I am curious why the following will not work in Python: > > class foo(object): > def bar(self): > print self.attr > > class duck(object): > attr = 3.14 > > foo.bar(duck()) Thanks to ever

Re: [Python-Dev] Duck-typing self

2009-02-18 Thread Greg Ewing
Christian Heimes wrote: In 2.x a class objects wrap their functions in a method wrapper. The method wrapper does the type check. You can get around the type check by using the im_func attribute of the method wrapper. You could probably also create a decorator that gives you something behaving

Re: [Python-Dev] Duck-typing self

2009-02-18 Thread Greg Ewing
Sebastian Rittau wrote: Is it a design decision that duck-typing self does not work or is there a technical reason? There's no technical reason as far as user-defined classes are concerned. I think it was introduced to help catch errors due to making inherited method calls to the wrong class,

Re: [Python-Dev] Duck-typing self

2009-02-18 Thread Christian Heimes
Steven Bethard wrote: >> Is it a design decision that duck-typing self does not work or is there a >> technical reason? From a practical standpoint it seems that being able to >> duck-type self has merit, for example in unit testing complex classes. > > Works for me in 3.0: It works in 3.0 becaus

Re: [Python-Dev] Duck-typing self

2009-02-18 Thread Steven Bethard
On Wed, Feb 18, 2009 at 2:32 PM, Sebastian Rittau wrote: > Hi! > > I am curious why the following will not work in Python: > > class foo(object): > def bar(self): > print self.attr > > class duck(object): > attr = 3.14 > > foo.bar(duck()) > > Is it a design decision that duck

[Python-Dev] Duck-typing self

2009-02-18 Thread Sebastian Rittau
Hi! I am curious why the following will not work in Python: class foo(object): def bar(self): print self.attr class duck(object): attr = 3.14 foo.bar(duck()) Is it a design decision that duck-typing self does not work or is there a technical reason? From