File: typing.py

package info (click to toggle)
python-cloup 3.0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 936 kB
  • sloc: python: 5,371; makefile: 120
file content (28 lines) | stat: -rw-r--r-- 801 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
__all__ = ['AnyCallable', 'MISSING', 'Possibly',  'Decorator', 'F']

from enum import Enum
from typing import Any, Callable, TypeVar, Union


# PEP-blessed solution for defining a Singleton type:
# https://peps.python.org/pep-0614/#motivation
class _Missing(Enum):
    flag = 'Missing'


MISSING = _Missing.flag
"""Singleton that works as a sentinel for a missing value.
Useful when None can't be used to play the role because it represents a valid
non-null value."""

_T = TypeVar('_T')
Possibly = Union[_Missing, _T]
"""Possibly[T] is like Optional[T] but uses MISSING for missing values."""

AnyCallable = Callable[..., Any]

F = TypeVar('F', bound=AnyCallable)
"""Type variable for a Callable."""

Decorator = Callable[[AnyCallable], AnyCallable]
"""Type alias for a simple function decorator."""