Skip to the content.

Type Hint for Literal

New in Python 3.8. See PEP 586.

Recipes

from typing import Literal

x: Literal[1, 2, True, False]  # one of 1, 2, True, False

More Details

References