[Python] Typehints in Python including the default values [closed]

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have a function that calls a bunch of other functions like this:

    def func_a(self, var_a:int=10, var_b:str = 'a') -> float:
    pass

    def func_b(self, var_c:int=10, var_d:str = 'b') -> float:
    pass

    def main_func(args_a, args_b):
    value_a = func_a(**args_a)
    value_b = func_b(**args_b)

    args_a = {"var_b":'d'}
    args_b = {"var_c":5}
    main_func(args_a, args_b)


    This works, However, somehow I would like to get all options to func_a as a dict with their possible inputs and the default values (e.g. args_a = {"var_a":10, "var_b": 'a'}. I also want the IDE to recognize this, similar as when I call a function, so I know what options there are and the default values.

    I've tried with dataclasses and TypeDicts but I have not managed to get the behavior that I'm looking for.

    Continue reading...

Compartilhe esta Página