forked from python-attrs/attrs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from typing import Any, Callable, Dict, Iterable, List, Optional, Mapping, Tuple, Type, TypeVar, Union, overload | ||
from . import exceptions | ||
from . import filters | ||
from . import converters | ||
from . import validators | ||
|
||
# typing -- | ||
|
||
C = TypeVar('C', bound=type) | ||
M = TypeVar('M', bound=Mapping) | ||
T = TypeVar('T', bound=tuple) | ||
I = TypeVar('I') | ||
|
||
ValidatorType = Callable[[object, 'Attribute', Any], Any] | ||
ConverterType = Callable[[Any], Any] | ||
FilterType = Callable[['Attribute', Any], bool] | ||
|
||
# _make -- | ||
|
||
class _CountingAttr: ... | ||
|
||
NOTHING : object | ||
|
||
class Attribute: | ||
__slots__ = ( | ||
"name", "default", "validator", "repr", "cmp", "hash", "init", | ||
"convert", "metadata", | ||
) | ||
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: ... | ||
|
||
# NOTE: the stub for `attr` returns Any so that static analysis passes when used in the form: x : int = attr() | ||
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: ... | ||
|
||
@overload | ||
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: ... | ||
@overload | ||
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]: ... | ||
|
||
def fields(cls: type) -> Tuple[Attribute, ...]: ... | ||
def validate(inst: object) -> None: ... | ||
|
||
class Factory: | ||
factory : Union[Callable[[Any], Any], Callable[[object, Any], Any]] | ||
takes_self : bool | ||
def __init__(self, factory: Union[Callable[[Any], Any], Callable[[object, Any], Any]], takes_self: bool = ...) -> None: ... | ||
|
||
def make_class(name, attrs: Union[List[_CountingAttr], Dict[str, _CountingAttr]], bases: Tuple[type, ...] = ..., **attributes_arguments) -> type: ... | ||
|
||
def and_(*validators: Iterable[ValidatorType]) -> ValidatorType: ... | ||
|
||
# _funcs -- | ||
|
||
# FIXME: having problems assigning a default to the factory typevars | ||
def asdict(inst: object, recurse: bool = ..., filter: Optional[FilterType] = ..., dict_factory: Callable[[], M] = ..., retain_collection_types: bool = ...) -> M: ... | ||
def astuple(inst: object, recurse: bool = ..., filter: Optional[FilterType] = ..., tuple_factory: Callable[[Iterable], T] = ..., retain_collection_types: bool = ...) -> T: ... | ||
def has(cls: type) -> bool: ... | ||
def assoc(inst: I, **changes) -> I: ... | ||
def evolve(inst: I, **changes) -> I: ... | ||
|
||
# _config -- | ||
|
||
def set_run_validators(run: bool) -> None: ... | ||
def get_run_validators() -> bool: ... | ||
|
||
# aliases | ||
s = attrs = attributes | ||
ib = attrib = attr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import ConverterType | ||
|
||
def optional(converter: ConverterType) -> ConverterType: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import List | ||
|
||
class FrozenInstanceError(AttributeError): | ||
msg : str = ... | ||
args : List[str] = ... | ||
|
||
class AttrsAttributeNotFoundError(ValueError): ... | ||
class NotAnAttrsClassError(ValueError): ... | ||
class DefaultAlreadySetError(RuntimeError): ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from typing import Union | ||
from . import Attribute, FilterType | ||
|
||
def include(*what: Union[type, Attribute]) -> FilterType: ... | ||
def exclude(*what: Union[type, Attribute]) -> FilterType: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Container, List, Union | ||
from . import ValidatorType | ||
|
||
def instance_of(type: type) -> ValidatorType: ... | ||
|
||
def provides(interface) -> ValidatorType: ... | ||
|
||
def optional(validator: Union[ValidatorType, List[ValidatorType]]) -> ValidatorType: ... | ||
|
||
def in_(options: Container) -> ValidatorType: ... |