次のコードスニペットが機能しない理由を説明できますか?Pythonで静的メソッドを渡す
class A:
@staticmethod
def f():
print('A.f')
dict = {'f': f}
def callMe(g):
g()
callMe(A.dict['f'])
それは
class A:
@staticmethod
def f():
print('A.f')
dict = {'f': f}
def callMe(g):
g()
callMe(A.f)
または
class A:
@staticmethod
def f():
print('A.f')
dict = {'f': lambda: A.f()}
def callMe(g):
g()
callMe(A.dict['f'])
にそれを変更することが期待される結果
を与え、InteresinglyTypeError: 'staticmethod' object is not callable
を生み出します
A.f
私の知る限り動作は、Python 2で同じと3. A
内部f
オブジェクトはdescriptor、しない静的メソッド自体は