[Python] How to specify "nullable" return type with type hints

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose I have a function:

    def get_some_date(some_argument: int=None) -> %datetime_or_None%:
    if some_argument is not None and some_argument == 1:
    return datetime.utcnow()
    else:
    return None


    How do I specify the return type for something that can be None?

    Continue reading...

Compartilhe esta Página