Is this a bug, or is it me?
Peter Otten
__peter__ at web.de
Fri Jan 18 17:27:58 EST 2008
cptnwillard wrote:
> I filed a bug report, and here is the short answer to my question:
> genexps are code blocks, and code blocks cannot see variables in class
> scopes. Congrats to Neil Cerutti who figured it out.
>
> Now here is another one for your enjoyment:
>
> class C:
> @staticmethod
> def f1(): pass
> F = { '1' : f1 }
>
> C().F['1']()
>
>>>> TypeError: 'staticmethod' object is not callable
>
>
> What do you think of this one?
If you want it to be callable you can subclass:
>>> class static(staticmethod):
... def __call__(self, *args, **kw):
... return self.__get__(object)(*args, **kw)
...
>>> class A(object):
... @static
... def f(x="yadda"): print x
... f()
...
yadda
>>> A.f()
yadda
>>> A().f()
yadda
Peter
More information about the Python-list
mailing list