[Python] Type hints with map like function?

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    Suppose I've got a map like function:

    def generate(data, per_element):
    for element in data:
    per_element(element)


    How can I add type-hints so that if I call generate(some_data, some_function) where some_data: List[SomeClass], I get a warning if SomeClass is missing a field used by some_function?

    As an example - with the following code:

    def some_function(x):
    print(x.value)

    some_data: List[int] = [1, 2, 3]

    generate(some_data, some_function)


    I would like to get a warning that int does not have the attribute value.

    Continue reading...

Compartilhe esta Página