[Python] Optional typing for more than a single type

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    Since the documentation only uses Optional with a single type (Optional[X]), I was wondering if Union is required if I have an argument that accepts either a string, a list, or None.

    def func(
    arg: Optional[str, list]
    )


    def func(
    arg: Optional[Union[str, list]]
    )

    Continue reading...

Compartilhe esta Página