Callable は type hint で関数で呼び出すことが出来る。
class PaymentProcessor:
def __init__(self, authorize_type: str):
if authorizer_type == 'sms':
self.authorize = authorize_sms
elif authorizer_type == 'email':
self.authorize = authorize_email
Callable の使い方は list に 実引数のリスト と 返り値の型 を記載する。
Callable[[引数], 返り値]
AuthorizeFunction = Callable[[], bool]
class PaymentProcessor:
def __init__(self, authorize: AuthorizerFunction):
self.authorize = authorize