| 1 |
from typing import TypeVar, overload, Callable, Any, Optional, Union, Sequence, Mapping, \ |
| 2 |
Protocol, ClassVar, Type |
| 3 |
from typing_extensions import TypeGuard |
| 4 |
|
| 5 |
from attr import Attribute as Attribute |
| 6 |
|
| 7 |
|
| 8 |
class AttrsInstance(Protocol): |
| 9 |
__attrs_attrs__: ClassVar[Any] |
| 10 |
|
| 11 |
|
| 12 |
_T = TypeVar('_T') |
| 13 |
_C = TypeVar('_C', bound=type) |
| 14 |
|
| 15 |
_ValidatorType = Callable[[Any, Any, _T], Any] |
| 16 |
_ConverterType = Callable[[Any], _T] |
| 17 |
_ValidatorArgType = Union[_ValidatorType[_T], Sequence[_ValidatorType[_T]]] |
| 18 |
|
| 19 |
@overload |
| 20 |
def define( |
| 21 |
maybe_cls: _C, |
| 22 |
*, |
| 23 |
these: Optional[Mapping[str, Any]] = ..., |
| 24 |
repr: bool = ..., |
| 25 |
unsafe_hash: Optional[bool]=None, |
| 26 |
hash: Optional[bool] = ..., |
| 27 |
init: bool = ..., |
| 28 |
slots: bool = ..., |
| 29 |
frozen: bool = ..., |
| 30 |
weakref_slot: bool = ..., |
| 31 |
str: bool = ..., |
| 32 |
auto_attribs: bool = ..., |
| 33 |
kw_only: bool = ..., |
| 34 |
cache_hash: bool = ..., |
| 35 |
auto_exc: bool = ..., |
| 36 |
eq: Optional[bool] = ..., |
| 37 |
order: Optional[bool] = ..., |
| 38 |
auto_detect: bool = ..., |
| 39 |
getstate_setstate: Optional[bool] = ..., |
| 40 |
on_setattr: Optional[object] = ..., |
| 41 |
) -> _C: ... |
| 42 |
@overload |
| 43 |
def define( |
| 44 |
maybe_cls: None = ..., |
| 45 |
*, |
| 46 |
these: Optional[Mapping[str, Any]] = ..., |
| 47 |
repr: bool = ..., |
| 48 |
unsafe_hash: Optional[bool]=None, |
| 49 |
hash: Optional[bool] = ..., |
| 50 |
init: bool = ..., |
| 51 |
slots: bool = ..., |
| 52 |
frozen: bool = ..., |
| 53 |
weakref_slot: bool = ..., |
| 54 |
str: bool = ..., |
| 55 |
auto_attribs: bool = ..., |
| 56 |
kw_only: bool = ..., |
| 57 |
cache_hash: bool = ..., |
| 58 |
auto_exc: bool = ..., |
| 59 |
eq: Optional[bool] = ..., |
| 60 |
order: Optional[bool] = ..., |
| 61 |
auto_detect: bool = ..., |
| 62 |
getstate_setstate: Optional[bool] = ..., |
| 63 |
on_setattr: Optional[object] = ..., |
| 64 |
) -> Callable[[_C], _C]: ... |
| 65 |
|
| 66 |
mutable = define |
| 67 |
frozen = define # they differ only in their defaults |
| 68 |
|
| 69 |
@overload |
| 70 |
def field( |
| 71 |
*, |
| 72 |
default: None = ..., |
| 73 |
validator: None = ..., |
| 74 |
repr: object = ..., |
| 75 |
hash: Optional[bool] = ..., |
| 76 |
init: bool = ..., |
| 77 |
metadata: Optional[Mapping[Any, Any]] = ..., |
| 78 |
converter: None = ..., |
| 79 |
factory: None = ..., |
| 80 |
kw_only: bool = ..., |
| 81 |
eq: Optional[bool] = ..., |
| 82 |
order: Optional[bool] = ..., |
| 83 |
on_setattr: Optional[_OnSetAttrArgType] = ..., |
| 84 |
alias: Optional[str] = ..., |
| 85 |
) -> Any: ... |
| 86 |
|
| 87 |
# This form catches an explicit None or no default and infers the type from the |
| 88 |
# other arguments. |
| 89 |
@overload |
| 90 |
def field( |
| 91 |
*, |
| 92 |
default: None = ..., |
| 93 |
validator: Optional[_ValidatorArgType[_T]] = ..., |
| 94 |
repr: object = ..., |
| 95 |
hash: Optional[bool] = ..., |
| 96 |
init: bool = ..., |
| 97 |
metadata: Optional[Mapping[Any, Any]] = ..., |
| 98 |
converter: Optional[_ConverterType] = ..., |
| 99 |
factory: Optional[Callable[[], _T]] = ..., |
| 100 |
kw_only: bool = ..., |
| 101 |
eq: Optional[bool] = ..., |
| 102 |
order: Optional[bool] = ..., |
| 103 |
on_setattr: Optional[object] = ..., |
| 104 |
alias: Optional[str] = ..., |
| 105 |
) -> _T: ... |
| 106 |
|
| 107 |
# This form catches an explicit default argument. |
| 108 |
@overload |
| 109 |
def field( |
| 110 |
*, |
| 111 |
default: _T, |
| 112 |
validator: Optional[_ValidatorArgType[_T]] = ..., |
| 113 |
repr: object = ..., |
| 114 |
hash: Optional[bool] = ..., |
| 115 |
init: bool = ..., |
| 116 |
metadata: Optional[Mapping[Any, Any]] = ..., |
| 117 |
converter: Optional[_ConverterType] = ..., |
| 118 |
factory: Optional[Callable[[], _T]] = ..., |
| 119 |
kw_only: bool = ..., |
| 120 |
eq: Optional[bool] = ..., |
| 121 |
order: Optional[bool] = ..., |
| 122 |
on_setattr: Optional[object] = ..., |
| 123 |
alias: Optional[str] = ..., |
| 124 |
) -> _T: ... |
| 125 |
|
| 126 |
# This form covers type=non-Type: e.g. forward references (str), Any |
| 127 |
@overload |
| 128 |
def field( |
| 129 |
*, |
| 130 |
default: Optional[_T] = ..., |
| 131 |
validator: Optional[_ValidatorArgType[_T]] = ..., |
| 132 |
repr: object = ..., |
| 133 |
hash: Optional[bool] = ..., |
| 134 |
init: bool = ..., |
| 135 |
metadata: Optional[Mapping[Any, Any]] = ..., |
| 136 |
converter: Optional[_ConverterType] = ..., |
| 137 |
factory: Optional[Callable[[], _T]] = ..., |
| 138 |
kw_only: bool = ..., |
| 139 |
eq: Optional[bool] = ..., |
| 140 |
order: Optional[bool] = ..., |
| 141 |
on_setattr: Optional[object] = ..., |
| 142 |
alias: Optional[str] = ..., |
| 143 |
) -> Any: ... |
| 144 |
|
| 145 |
def evolve(inst: _T, **changes: Any) -> _T: ... |
| 146 |
def assoc(inst: _T, **changes: Any) -> _T: ... |
| 147 |
def has(cls: type) -> TypeGuard[Type[AttrsInstance]]: ... |
| 148 |
def fields(cls: Type[AttrsInstance]) -> Any: ... |