|
| 1 | +from typing import Any, Callable, Dict, Iterable, List, Optional, Mapping, Tuple, Type, TypeVar, Union, overload |
| 2 | +from . import exceptions |
| 3 | +from . import filters |
| 4 | +from . import converters |
| 5 | +from . import validators |
| 6 | + |
| 7 | +# typing -- |
| 8 | + |
| 9 | +C = TypeVar('C', bound=type) |
| 10 | +M = TypeVar('M', bound=Mapping) |
| 11 | +T = TypeVar('T', bound=tuple) |
| 12 | +I = TypeVar('I') |
| 13 | + |
| 14 | +ValidatorType = Callable[[object, 'Attribute', Any], Any] |
| 15 | +ConverterType = Callable[[Any], Any] |
| 16 | +FilterType = Callable[['Attribute', Any], bool] |
| 17 | + |
| 18 | +# _make -- |
| 19 | + |
| 20 | +class _CountingAttr: ... |
| 21 | + |
| 22 | +NOTHING : object |
| 23 | + |
| 24 | +class Attribute: |
| 25 | + __slots__ = ( |
| 26 | + "name", "default", "validator", "repr", "cmp", "hash", "init", |
| 27 | + "convert", "metadata", |
| 28 | + ) |
| 29 | + def __init__(self, name: str, default: Any, validator: Optional[Union[ValidatorType, List[ValidatorType]]], repr: bool, cmp: bool, hash: Optional[bool], init: bool, convert: Optional[ConverterType] = ..., metadata: Mapping = ...) -> None: ... |
| 30 | + |
| 31 | +# NOTE: the stub for `attr` returns Any so that static analysis passes when used in the form: x : int = attr() |
| 32 | +def attr(default: Any = ..., validator: Optional[Union[ValidatorType, List[ValidatorType]]] = ..., repr: bool = ..., cmp: bool = ..., hash: Optional[bool] = ..., init: bool = ..., convert: Optional[ConverterType] = ..., metadata: Mapping = ...) -> Any: ... |
| 33 | + |
| 34 | +@overload |
| 35 | +def attributes(maybe_cls: C = ..., these: Optional[Dict[str, _CountingAttr]] = ..., repr_ns: Optional[str] = ..., repr: bool = ..., cmp: bool = ..., hash: Optional[bool] = ..., init: bool = ..., slots: bool = ..., frozen: bool = ..., str: bool = ...) -> C: ... |
| 36 | +@overload |
| 37 | +def attributes(maybe_cls: None = ..., these: Optional[Dict[str, _CountingAttr]] = ..., repr_ns: Optional[str] = ..., repr: bool = ..., cmp: bool = ..., hash: Optional[bool] = ..., init: bool = ..., slots: bool = ..., frozen: bool = ..., str: bool = ...) -> Callable[[C], C]: ... |
| 38 | + |
| 39 | +def fields(cls: type) -> Tuple[Attribute, ...]: ... |
| 40 | +def validate(inst: object) -> None: ... |
| 41 | + |
| 42 | +class Factory: |
| 43 | + factory : Union[Callable[[Any], Any], Callable[[object, Any], Any]] |
| 44 | + takes_self : bool |
| 45 | + def __init__(self, factory: Union[Callable[[Any], Any], Callable[[object, Any], Any]], takes_self: bool = ...) -> None: ... |
| 46 | + |
| 47 | +def make_class(name, attrs: Union[List[_CountingAttr], Dict[str, _CountingAttr]], bases: Tuple[type, ...] = ..., **attributes_arguments) -> type: ... |
| 48 | + |
| 49 | +def and_(*validators: Iterable[ValidatorType]) -> ValidatorType: ... |
| 50 | + |
| 51 | +# _funcs -- |
| 52 | + |
| 53 | +# FIXME: having problems assigning a default to the factory typevars |
| 54 | +def asdict(inst: object, recurse: bool = ..., filter: Optional[FilterType] = ..., dict_factory: Callable[[], M] = ..., retain_collection_types: bool = ...) -> M: ... |
| 55 | +def astuple(inst: object, recurse: bool = ..., filter: Optional[FilterType] = ..., tuple_factory: Callable[[Iterable], T] = ..., retain_collection_types: bool = ...) -> T: ... |
| 56 | +def has(cls: type) -> bool: ... |
| 57 | +def assoc(inst: I, **changes) -> I: ... |
| 58 | +def evolve(inst: I, **changes) -> I: ... |
| 59 | + |
| 60 | +# _config -- |
| 61 | + |
| 62 | +def set_run_validators(run: bool) -> None: ... |
| 63 | +def get_run_validators() -> bool: ... |
| 64 | + |
| 65 | +# aliases |
| 66 | +s = attrs = attributes |
| 67 | +ib = attrib = attr |
0 commit comments