def filter_message(prefix: str): def inner_check(func: typing.Callable[[str], None]): def inner_deeper_check(arg: str): if arg.startswith(prefix): print('Checking prefix....OK') func(arg) print('post process...OK') else: print('Checking prefix....Failed') print('access denied') return inner_deeper_check return inner_check @filter_message(prefix="test") def orig_func(arg1: str): print(f"arg1: {arg1}") if __name__ == "__main__": orig_func("Hello World!") orig_func("test: Hello World!")