Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/click/_utils.py: 82%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

22 statements  

1from __future__ import annotations 

2 

3import enum 

4import typing as t 

5 

6 

7class Sentinel(enum.Enum): 

8 """Enum used to define sentinel values. 

9 

10 .. seealso:: 

11 

12 `PEP 661 - Sentinel Values <https://peps.python.org/pep-0661/>`_. 

13 """ 

14 

15 UNSET = object() 

16 FLAG_NEEDS_VALUE = object() 

17 

18 def __repr__(self) -> str: 

19 return f"{self.__class__.__name__}.{self.name}" 

20 

21 def __copy__(self) -> Sentinel: 

22 return self 

23 

24 def __deepcopy__(self, memo: dict[int, t.Any]) -> Sentinel: 

25 return self 

26 

27 def __reduce_ex__(self, protocol: object) -> tuple[t.Any, ...]: 

28 return getattr, (self.__class__, self.name) 

29 

30 

31UNSET: t.Literal[Sentinel.UNSET] = Sentinel.UNSET 

32"""Sentinel used to indicate that a value is not set.""" 

33 

34FLAG_NEEDS_VALUE: t.Literal[Sentinel.FLAG_NEEDS_VALUE] = Sentinel.FLAG_NEEDS_VALUE 

35"""Sentinel used to indicate an option was passed as a flag without a 

36value but is not a flag option. 

37 

38``Option.consume_value`` uses this to prompt or use the ``flag_value``. 

39""" 

40 

41T_UNSET: t.TypeAlias = t.Literal[Sentinel.UNSET] 

42"""Type hint for the :data:`UNSET` sentinel value.""" 

43 

44T_FLAG_NEEDS_VALUE: t.TypeAlias = t.Literal[Sentinel.FLAG_NEEDS_VALUE] 

45"""Type hint for the :data:`FLAG_NEEDS_VALUE` sentinel value."""