--- /dev/null
+from typing import Any, Callable, Dict, Generic, List, Optional, Sequence, Mapping, Tuple, Type, TypeVar, Union, overload\r
+# `import X as X` is required to make these public\r
+from . import exceptions as exceptions\r
+from . import filters as filters\r
+from . import converters as converters\r
+from . import validators as validators\r
+\r
+_T = TypeVar('_T')\r
+_C = TypeVar('_C', bound=type)\r
+\r
+_ValidatorType = Callable[[Any, Attribute, _T], Any]\r
+_ConverterType = Callable[[Any], _T]\r
+_FilterType = Callable[[Attribute, Any], bool]\r
+# FIXME: in reality, if multiple validators are passed they must be in a list or tuple,\r
+# but those are invariant and so would prevent subtypes of _ValidatorType from working\r
+# when passed in a list or tuple.\r
+_ValidatorArgType = Union[_ValidatorType[_T], Sequence[_ValidatorType[_T]]]\r
+\r
+# _make --\r
+\r
+NOTHING: object\r
+\r
+# NOTE: Factory lies about its return type to make this possible: `x: List[int] = Factory(list)`\r
+# Work around mypy issue #4554 in the common case by using an overload.\r
+@overload\r
+def Factory(factory: Callable[[], _T]) -> _T: ...\r
+@overload\r
+def Factory(factory: Union[Callable[[Any], _T], Callable[[], _T]], takes_self: bool = ...) -> _T: ...\r
+\r
+class Attribute(Generic[_T]):\r
+ name: str\r
+ default: Optional[_T]\r
+ validator: Optional[_ValidatorType[_T]]\r
+ repr: bool\r
+ cmp: bool\r
+ hash: Optional[bool]\r
+ init: bool\r
+ converter: Optional[_ConverterType[_T]]\r
+ metadata: Dict[Any, Any]\r
+ type: Optional[Type[_T]]\r
+ def __lt__(self, x: Attribute) -> bool: ...\r
+ def __le__(self, x: Attribute) -> bool: ...\r
+ def __gt__(self, x: Attribute) -> bool: ...\r
+ def __ge__(self, x: Attribute) -> bool: ...\r
+\r
+\r
+# NOTE: We had several choices for the annotation to use for type arg:\r
+# 1) Type[_T]\r
+# - Pros: works in PyCharm without plugin support\r
+# - Cons: produces less informative error in the case of conflicting TypeVars\r
+# e.g. `attr.ib(default='bad', type=int)`\r
+# 2) Callable[..., _T]\r
+# - Pros: more informative errors than #1\r
+# - Cons: validator tests results in confusing error.\r
+# e.g. `attr.ib(type=int, validator=validate_str)`\r
+# 3) type (and do all of the work in the mypy plugin)\r
+# - Pros: in mypy, the behavior of type argument is exactly the same as with\r
+# annotations.\r
+# - Cons: completely disables type inspections in PyCharm when using the\r
+# type arg.\r
+# We chose option #1 until either PyCharm adds support for attrs, or python 2\r
+# reaches EOL.\r
+\r
+# NOTE: If you update these, update `ib` and `attr` below.\r
+\r
+# `attr` lies about its return type to make the following possible:\r
+# attr() -> Any\r
+# attr(8) -> int\r
+# attr(validator=<some callable>) -> Whatever the callable expects.\r
+# This makes this type of assignments possible:\r
+# x: int = attr(8)\r
+#\r
+# This form catches explicit None or no default but with no other arguments returns Any.\r
+@overload\r
+def attrib(default: None = ...,\r
+ validator: None = ...,\r
+ repr: bool = ...,\r
+ cmp: bool = ...,\r
+ hash: Optional[bool] = ...,\r
+ init: bool = ...,\r
+ convert: None = ...,\r
+ metadata: Optional[Mapping[Any, Any]] = ...,\r
+ type: None = ...,\r
+ converter: None = ...,\r
+ factory: None = ...,\r
+ ) -> Any: ...\r
+# This form catches an explicit None or no default and infers the type from the other arguments.\r
+@overload\r
+def attrib(default: None = ...,\r
+ validator: Optional[_ValidatorArgType[_T]] = ...,\r
+ repr: bool = ...,\r
+ cmp: bool = ...,\r
+ hash: Optional[bool] = ...,\r
+ init: bool = ...,\r
+ convert: Optional[_ConverterType[_T]] = ...,\r
+ metadata: Optional[Mapping[Any, Any]] = ...,\r
+ type: Optional[Type[_T]] = ...,\r
+ converter: Optional[_ConverterType[_T]] = ...,\r
+ factory: Optional[Callable[[], _T]] = ...,\r
+ ) -> _T: ...\r
+# This form catches an explicit default argument.\r
+@overload\r
+def attrib(default: _T,\r
+ validator: Optional[_ValidatorArgType[_T]] = ...,\r
+ repr: bool = ...,\r
+ cmp: bool = ...,\r
+ hash: Optional[bool] = ...,\r
+ init: bool = ...,\r
+ convert: Optional[_ConverterType[_T]] = ...,\r
+ metadata: Optional[Mapping[Any, Any]] = ...,\r
+ type: Optional[Type[_T]] = ...,\r
+ converter: Optional[_ConverterType[_T]] = ...,\r
+ factory: Optional[Callable[[], _T]] = ...,\r
+ ) -> _T: ...\r
+# This form covers type=non-Type: e.g. forward references (str), Any\r
+@overload\r
+def attrib(default: Optional[_T] = ...,\r
+ validator: Optional[_ValidatorArgType[_T]] = ...,\r
+ repr: bool = ...,\r
+ cmp: bool = ...,\r
+ hash: Optional[bool] = ...,\r
+ init: bool = ...,\r
+ convert: Optional[_ConverterType[_T]] = ...,\r
+ metadata: Optional[Mapping[Any, Any]] = ...,\r
+ type: object = ...,\r
+ converter: Optional[_ConverterType[_T]] = ...,\r
+ factory: Optional[Callable[[], _T]] = ...,\r
+ ) -> Any: ...\r
+\r
+\r
+# NOTE: If you update these, update `s` and `attributes` below.\r
+@overload\r
+def attrs(maybe_cls: _C,\r
+ these: Optional[Dict[str, Any]] = ...,\r
+ repr_ns: Optional[str] = ...,\r
+ repr: bool = ...,\r
+ cmp: bool = ...,\r
+ hash: Optional[bool] = ...,\r
+ init: bool = ...,\r
+ slots: bool = ...,\r
+ frozen: bool = ...,\r
+ str: bool = ...,\r
+ auto_attribs: bool = ...) -> _C: ...\r
+@overload\r
+def attrs(maybe_cls: None = ...,\r
+ these: Optional[Dict[str, Any]] = ...,\r
+ repr_ns: Optional[str] = ...,\r
+ repr: bool = ...,\r
+ cmp: bool = ...,\r
+ hash: Optional[bool] = ...,\r
+ init: bool = ...,\r
+ slots: bool = ...,\r
+ frozen: bool = ...,\r
+ str: bool = ...,\r
+ auto_attribs: bool = ...) -> Callable[[_C], _C]: ...\r
+\r
+\r
+# TODO: add support for returning NamedTuple from the mypy plugin\r
+class _Fields(Tuple[Attribute, ...]):\r
+ def __getattr__(self, name: str) -> Attribute: ...\r
+\r
+def fields(cls: type) -> _Fields: ...\r
+def fields_dict(cls: type) -> Dict[str, Attribute]: ...\r
+def validate(inst: Any) -> None: ...\r
+\r
+# TODO: add support for returning a proper attrs class from the mypy plugin\r
+# we use Any instead of _CountingAttr so that e.g. `make_class('Foo', [attr.ib()])` is valid\r
+def make_class(name: str,\r
+ attrs: Union[List[str], Tuple[str, ...], Dict[str, Any]],\r
+ bases: Tuple[type, ...] = ...,\r
+ repr_ns: Optional[str] = ...,\r
+ repr: bool = ...,\r
+ cmp: bool = ...,\r
+ hash: Optional[bool] = ...,\r
+ init: bool = ...,\r
+ slots: bool = ...,\r
+ frozen: bool = ...,\r
+ str: bool = ...,\r
+ auto_attribs: bool = ...) -> type: ...\r
+\r
+# _funcs --\r
+\r
+# TODO: add support for returning TypedDict from the mypy plugin\r
+# FIXME: asdict/astuple do not honor their factory args. waiting on one of these:\r
+# https://github.com/python/mypy/issues/4236\r
+# https://github.com/python/typing/issues/253\r
+def asdict(inst: Any,\r
+ recurse: bool = ...,\r
+ filter: Optional[_FilterType] = ...,\r
+ dict_factory: Type[Mapping[Any, Any]] = ...,\r
+ retain_collection_types: bool = ...) -> Dict[str, Any]: ...\r
+# TODO: add support for returning NamedTuple from the mypy plugin\r
+def astuple(inst: Any,\r
+ recurse: bool = ...,\r
+ filter: Optional[_FilterType] = ...,\r
+ tuple_factory: Type[Sequence] = ...,\r
+ retain_collection_types: bool = ...) -> Tuple[Any, ...]: ...\r
+def has(cls: type) -> bool: ...\r
+def assoc(inst: _T, **changes: Any) -> _T: ...\r
+def evolve(inst: _T, **changes: Any) -> _T: ...\r
+\r
+# _config --\r
+\r
+def set_run_validators(run: bool) -> None: ...\r
+def get_run_validators() -> bool: ...\r
+\r
+\r
+# aliases --\r
+\r
+s = attributes = attrs\r
+ib = attr = attrib\r
+dataclass = attrs # Technically, partial(attrs, auto_attribs=True) ;)\r