>>>
x = 'abc' expect = 'abcabcabc'
class C(object):
- def f(x):
- return x*3
call = staticmethod(f)
assert expect == C()(x) # works great
- # straightforward from docs
E = type('E',(object,),dict(call=staticmethod(C.call)))
assert expect == E()(x) # works great, why must I
- # repeat staticmethod?
def f(x):
- return x*3
class G(object):
call = staticmethod(f)
assert expect == G()(x) # works great, works as I expect
# My opportunity to make a static method has passed?
I = type('I',(C,),dict(call = staticmethod(C.f)))
try:
- assert expect == I()(x)
except TypeError,info: # I don\'t understand.
- assert info.message.startswith('unbound method f()')
# Staticness lost?
F = type('F',(object,),dict(call=C.call))
try:
- assert expect == F()(x)
except TypeError,info: # misunderstood,
- assert info.message.startswith('f() takes exactly 1 argument (2 given)')