Strange error with unbound method
Robin Thomas
robin.thomas at starmedia.net
Mon Apr 16 13:20:57 EDT 2001
At 04:32 PM 4/16/01 +0000, Remco Gerlich wrote:
>Fernando RodrÃguez <spamers at must.die> wrote in comp.lang.python:
> > I have a class called ParaStyle (see code below). This class has a
> > method called makeBlackAndWhite that returns a new instance of class
> > ParaStyle.
>
>In the first case you call a method on a class. That's not possible.
>
>The second case, since the list contains *instances*, everything is ok. You
>call the method on the instance.
What are you talking about? Calling unbound methods with instance as first
argument is not just legal, it's moral!
class Foo:
def method(self): return self
f = Foo()
Foo.method(f)
# succeeds
l = []
for i in range(100): l.append(Foo())
map(Foo.method, l)
# also succeeds, with flying colors
I asked Fernando (privately) whether his BaseObject base class was doing
metaclass weirdness. It's either metaclass weirdness, or that paraStyles
actually contains a non-instance-of-ParaStyle, that could cause his problem.
--
Robin Thomas
Engineering
StarMedia Network, Inc.
robin.thomas at starmedia.net
More information about the Python-list
mailing list