Beta/venv/lib/python3.12/site-packages/click/_utils.py

37 lines
996 B
Python
Raw Normal View History

2026-02-06 22:23:20 +01:00
from __future__ import annotations
import enum
import typing as t
class Sentinel(enum.Enum):
"""Enum used to define sentinel values.
.. seealso::
`PEP 661 - Sentinel Values <https://peps.python.org/pep-0661/>`_.
"""
UNSET = object()
FLAG_NEEDS_VALUE = object()
def __repr__(self) -> str:
return f"{self.__class__.__name__}.{self.name}"
2026-06-16 17:09:34 +00:00
UNSET: t.Literal[Sentinel.UNSET] = Sentinel.UNSET
2026-02-06 22:23:20 +01:00
"""Sentinel used to indicate that a value is not set."""
2026-06-16 17:09:34 +00:00
FLAG_NEEDS_VALUE: t.Literal[Sentinel.FLAG_NEEDS_VALUE] = Sentinel.FLAG_NEEDS_VALUE
2026-02-06 22:23:20 +01:00
"""Sentinel used to indicate an option was passed as a flag without a
value but is not a flag option.
``Option.consume_value`` uses this to prompt or use the ``flag_value``.
"""
2026-06-16 17:09:34 +00:00
T_UNSET: t.TypeAlias = t.Literal[Sentinel.UNSET]
2026-02-06 22:23:20 +01:00
"""Type hint for the :data:`UNSET` sentinel value."""
2026-06-16 17:09:34 +00:00
T_FLAG_NEEDS_VALUE: t.TypeAlias = t.Literal[Sentinel.FLAG_NEEDS_VALUE]
2026-02-06 22:23:20 +01:00
"""Type hint for the :data:`FLAG_NEEDS_VALUE` sentinel value."""