1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to annotate different iterable types with same items' type?

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    For example:

    How to set the argument type to: list, which contains ints and floats, or tuple, which contains ints and floats?

    tried:

    from typing import List, Tuple, Union

    def some(arg: Union[List, Tuple][int, float]): ...


    Raises

    TypeError: typing.Union[typing.List, typing.Tuple] is not a generic class


    The general question is for any iterables' types' combinations and any content types.

    Continue reading...

Compartilhe esta Página