Debian Codegraph @

cloup/typing.py

raw
1 __all__ = ['AnyCallable', 'MISSING', 'Possibly', 'Decorator', 'F']
2
3 from enum import Enum
4 from typing import Any, Callable, TypeVar, Union
5
6
7 # PEP-blessed solution for defining a Singleton type:
8 # https://peps.python.org/pep-0614/#motivation
9 class _Missing(Enum):
10 flag = 'Missing'
11
12
13 MISSING = _Missing.flag
14 """Singleton that works as a sentinel for a missing value.
15 Useful when None can't be used to play the role because it represents a valid
16 non-null value."""
17
18 _T = TypeVar('_T')
19 Possibly = Union[_Missing, _T]
20 """Possibly[T] is like Optional[T] but uses MISSING for missing values."""
21
22 AnyCallable = Callable[..., Any]
23
24 F = TypeVar('F', bound=AnyCallable)
25 """Type variable for a Callable."""
26
27 Decorator = Callable[[AnyCallable], AnyCallable]
28 """Type alias for a simple function decorator."""