[Python] Literal from typing [duplicate]

Discussão em 'Python' iniciado por Stack, Janeiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to figure out how Literal from the typing module works.

    I tried the following example from PEP 586:

    from typing import Literal

    def accepts_only_four(x: Literal[4]) -> None:
    pass

    accepts_only_four(4) # OK
    accepts_only_four(19) # Rejected


    In my case nothing is rejected. I am running Python 3.11.5 on Windows 11. What am I doing wrong?

    Continue reading...

Compartilhe esta Página