File: choices.pyi

package info (click to toggle)
python-django-stubs 5.2.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,832 kB
  • sloc: python: 5,185; makefile: 15; sh: 8
file content (41 lines) | stat: -rw-r--r-- 1,448 bytes parent folder | download
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
29
30
31
32
33
34
35
36
37
38
39
40
41
from collections.abc import Callable, Iterable, Iterator, Mapping
from typing import Any, Protocol, TypeAlias, TypeVar, type_check_only

from django.db.models import Choices

_Choice: TypeAlias = tuple[Any, Any]
_ChoiceNamedGroup: TypeAlias = tuple[str, Iterable[_Choice]]
_Choices: TypeAlias = Iterable[_Choice | _ChoiceNamedGroup]
_ChoicesMapping: TypeAlias = Mapping[Any, Any]
_ChoicesInput: TypeAlias = _Choices | _ChoicesMapping | type[Choices] | Callable[[], _Choices | _ChoicesMapping]  # noqa: PYI047

@type_check_only
class _ChoicesCallable(Protocol):
    def __call__(self) -> _Choices: ...

class BaseChoiceIterator:
    def __getitem__(self, index: int) -> _Choice | _ChoiceNamedGroup: ...
    def __iter__(self) -> Iterator[_Choice | _ChoiceNamedGroup]: ...

class BlankChoiceIterator(BaseChoiceIterator):
    choices: _Choices
    blank_choice: _Choices
    def __init__(self, choices: _Choices, blank_choice: _Choices) -> None: ...

class CallableChoiceIterator(BaseChoiceIterator):
    func: _ChoicesCallable
    def __init__(self, func: _ChoicesCallable) -> None: ...

_V = TypeVar("_V")
_L = TypeVar("_L")

def flatten_choices(choices: Iterable[tuple[_V, _L | Iterable[tuple[_V, _L]]]]) -> Iterator[tuple[_V, _L]]: ...
def normalize_choices(value: Any, *, depth: int = 0) -> Any: ...

__all__ = [
    "BaseChoiceIterator",
    "BlankChoiceIterator",
    "CallableChoiceIterator",
    "flatten_choices",
    "normalize_choices",
]