I'm trying to make a class static method, and then use it in a class variable as a callback. I'm running into a problem with the static method not being callable that I can't figure out:
from dataclasses import dataclass
from typing import Callable
@dataclass
class Option:
txt: str
callback: Callable
class Window:
@staticmethod
def _doit(a=1):
print('do it with a', a)
cvar = Option(txt='doit', callback=_doit)
w1 = Window()
w1._doit()
# works fine
Window._doit()
# works fine
w1.cvar.callback()
# this fails
The last call above fails with "TypeError: 'staticmethod' object is not callable"
.
I'm not sure why here, but even more confusing to me is if I remove the @staticmethod
line, then things work 'correctly' - with all 3 calls in the code working.
I know I must being doing something stupid wrong, but I can't figure out what's wrong with the above ...any help?
thanks!