For Python 3, it turned out as a good practise for me, to hint data types for function parameters and return types. For example:
def icecream_factory(taste: str='Banana') -> Ice:
ice = Ice(taste)
ice.add_cream()
return ice
This works perfectly for all simple data types and classes. But now I need to use this with a "function pointer":
class NotificationRegister:
def __init__(self):
self.__function_list = list()
""":type: list[?????]"""
def register(self, function_pointer: ?????) -> None:
self.__function_list.append(function_pointer)
def callback():
pass
notification_register = NotificationRegister()
notification_register.register(callback)
What must be put at the ?????
to make clear that a function pointer is required here? I tried function
, because type(callback)
is <class 'function'>
, but the keyword function
is not defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With