I'd like to dynamically create a function in memory, with a type hint of the argument. I do have some working code, but it feels extremely hacky and fragile.
import typing
func_name = 'some_function_name'
req_type=int
a = None
exec(f'''def {func_name}(my_argument:{req_type.__name__}): pass
a = {func_name}''')
print(a) # <function some_function_name at 0x000001B89F3311F0>
print(typing.get_type_hints(a)) # {'my_argument': <class 'int'>}
There has got to be a better way to do this. Any suggestions?