News for hackers. Stuff that matters.
Re:Strict Python function parameters by ShamelessC on Sunday January 23, 2022 @02:13PM (#30049341)
Yeah, this is the correct answer and it works with functions or objects.

This is commonly used to implement logging callbacks e.g.

    from collections.abc import Callable
    
    def log_fn(message: str = ''):
        print(f'This is your log: {message}')
    
    def run_read_file(file_to_read:str, log_handler: Callable=log_fn):
        contents = open(file_to_read).readlines()
        for line in contents:
            log_handler(message=line)

There are no comments on this comment yet.