Inconsistency of special class method lookup?

anne.nospam01 at wangnick.de anne.nospam01 at wangnick.de
Sat Mar 11 04:53:15 EST 2006


Folks,

I'm running into the following issue. A staticmethod of a class seems
not to be accepted as a special class method of the class object
itself. For example:

class Foo(object):
	def __len__(): return 2
	__len__ = staticmethod(__len__)
print len(Foo)
>>>
Traceback (most recent call last):
  File "C:/Dokumente und Einstellungen/All Users/Dokumente/foo.py",
line 4, in ?
    print len(Foo)
TypeError: len() of unsized object

However, the following works:

class FooType(type):
	def __len__(self): return self.l()
class Foo(object):
	__metaclass__ = FooType
	def l(): return 3
	l = staticmethod(l)
print len(Foo)
>>>
3

Any good reason why the lookup process doesn't find __len__ as
staticmethod of the class?

Regards,
Sebastian (posting using the account of my wife)




More information about the Python-list mailing list