Код: Выделить всё
def run_thing(cb: Callback) -> Result:
w: Widget = make_widget()
res: Result = cb(w)
return res
Код: Выделить всё
# Option 1: Callable
# https://docs.python.org/3/library/typing.html#annotating-callables
Callback = typing.Callable[[Widget],Result]
Код: Выделить всё
# Option 2: Protocol
# https://docs.python.org/3/library/typing.html#typing.Protocol
class Callback(typing.Protocol):
def __call__(self,w: Widget) -> Result:
...
Подробнее здесь: https://stackoverflow.com/questions/770 ... s-callable