[Python] How to specify dict_values in type hints?

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    My function recives the values from a dictionary. The following MWE should give an impression:

    def f(x):
    print([y for y in x])

    f({'a': 0, 'b': 1}.values()) #prints [0, 1]


    The type of x is not dict nor list but dict_values. However def f(x: dict_values): gives the NameError: name 'dict_values' is not defined.

    So, how to specify dict_values in type hints?

    Continue reading...

Compartilhe esta Página