Skip to content
Myr

_utils.py

This file

Path

src/click/_utils.py

36 lines · 996 bytes · Python

Last changed by

Fix sentinel typing and its uses in parser (#3396)Andreas Backxbefore adoption73e1550

History of this file

Take it

1from __future__ import annotations23import enum4import typing as t567class Sentinel(enum.Enum):8    """Enum used to define sentinel values.910    .. seealso::1112        `PEP 661 - Sentinel Values <https://peps.python.org/pep-0661/>`_.13    """1415    UNSET = object()16    FLAG_NEEDS_VALUE = object()1718    def __repr__(self) -> str:19        return f"{self.__class__.__name__}.{self.name}"202122UNSET: t.Literal[Sentinel.UNSET] = Sentinel.UNSET23"""Sentinel used to indicate that a value is not set."""2425FLAG_NEEDS_VALUE: t.Literal[Sentinel.FLAG_NEEDS_VALUE] = Sentinel.FLAG_NEEDS_VALUE26"""Sentinel used to indicate an option was passed as a flag without a27value but is not a flag option.2829``Option.consume_value`` uses this to prompt or use the ``flag_value``.30"""3132T_UNSET: t.TypeAlias = t.Literal[Sentinel.UNSET]33"""Type hint for the :data:`UNSET` sentinel value."""3435T_FLAG_NEEDS_VALUE: t.TypeAlias = t.Literal[Sentinel.FLAG_NEEDS_VALUE]36"""Type hint for the :data:`FLAG_NEEDS_VALUE` sentinel value."""