1
1
from typing import Any , Callable , Dict , Generic , 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
2
+ # `import X as X` is required to expose these to mypy. otherwise they are invisible
3
+ from . import exceptions as exceptions
4
+ from . import filters as filters
5
+ from . import converters as converters
6
+ from . import validators as validators
6
7
7
8
# typing --
8
9
9
10
_T = TypeVar ('_T' )
10
- T = TypeVar ('T' )
11
11
_C = TypeVar ('_C' , bound = type )
12
12
_M = TypeVar ('_M' , bound = Mapping )
13
13
_I = TypeVar ('_I' , bound = Iterable )
14
14
15
- ValidatorType = Callable [[object , 'Attribute' , Any ], Any ]
15
+ _ValidatorType = Callable [[Any , 'Attribute' , Any ], Any ]
16
16
# FIXME: Bind to attribute type?
17
- ConverterType = Callable [[Any ], Any ]
18
- FilterType = Callable [['Attribute' , Any ], bool ]
17
+ _ConverterType = Callable [[Any ], Any ]
18
+ _FilterType = Callable [['Attribute' , Any ], bool ]
19
19
20
20
# _make --
21
21
@@ -24,37 +24,37 @@ class _CountingAttr: ...
24
24
NOTHING : object
25
25
26
26
class Factory (Generic [_T ]):
27
- factory : Union [Callable [[], _T ], Callable [[object ], _T ]]
27
+ factory : Union [Callable [[], _T ], Callable [[Any ], _T ]]
28
28
takes_self : bool
29
- def __init__ (self , factory : Union [Callable [[], _T ], Callable [[object ], _T ]], takes_self : bool = ...) -> None : ...
29
+ def __init__ (self , factory : Union [Callable [[], _T ], Callable [[Any ], _T ]], takes_self : bool = ...) -> None : ...
30
30
31
31
class Attribute :
32
32
__slots__ = ("name" , "default" , "validator" , "repr" , "cmp" , "hash" , "init" , "convert" , "metadata" , "type" )
33
- 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 = ..., type : Union [type , Factory ] = ...) -> None : ...
33
+ def __init__ (self , name : str , default : Any , validator : Optional [Union [_ValidatorType , List [_ValidatorType ], Tuple [ _ValidatorType , ...]]] , repr : bool , cmp : bool , hash : Optional [bool ], init : bool , convert : Optional [_ConverterType ] = ..., metadata : Mapping = ..., type : Union [type , Factory ] = ...) -> None : ...
34
34
35
35
# NOTE: this overload for `attr` returns Any so that static analysis passes when used in the form: x : int = attr()
36
- # @overload
37
- # 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: ...
38
- # @overload
39
- def attr (default : Any = ..., validator : Optional [Union [ValidatorType , List [ValidatorType ]]] = ..., repr : bool = ..., cmp : bool = ..., hash : Optional [bool ] = ..., init : bool = ..., convert : Optional [ConverterType ] = ..., metadata : Mapping = ..., type : Type [T ] = ...) -> T : ...
36
+ @overload
37
+ def attr (default : Any = ..., validator : Optional [Union [_ValidatorType , List [_ValidatorType ], Tuple [ _ValidatorType , ...]]] = ..., repr : bool = ..., cmp : bool = ..., hash : Optional [bool ] = ..., init : bool = ..., convert : Optional [_ConverterType ] = ..., metadata : Mapping = ...) -> Any : ...
38
+ @overload
39
+ def attr (default : Any = ..., validator : Optional [Union [_ValidatorType , List [_ValidatorType ], Tuple [ _ValidatorType , ...]]] = ..., repr : bool = ..., cmp : bool = ..., hash : Optional [bool ] = ..., init : bool = ..., convert : Optional [_ConverterType ] = ..., metadata : Mapping = ..., type : Type [_T ] = ...) -> _T : ...
40
40
41
41
@overload
42
42
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 : ...
43
43
@overload
44
44
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 ]: ...
45
45
46
46
def fields (cls : type ) -> Tuple [Attribute , ...]: ...
47
- def validate (inst : object ) -> None : ...
47
+ def validate (inst : Any ) -> None : ...
48
48
49
49
def make_class (name , attrs : Union [List [_CountingAttr ], Dict [str , _CountingAttr ]], bases : Tuple [type , ...] = ..., ** attributes_arguments ) -> type : ...
50
50
51
51
# _funcs --
52
52
53
53
# FIXME: having problems assigning a default to the factory typevars
54
- # def asdict(inst: object , recurse: bool = ..., filter: Optional[FilterType ] = ..., dict_factory: Type[_M] = dict, retain_collection_types: bool = ...) -> _M[str, Any]: ...
55
- # def astuple(inst: object , recurse: bool = ..., filter: Optional[FilterType ] = ..., tuple_factory: Type[_I] = tuple, retain_collection_types: bool = ...) -> _I: ...
56
- def asdict (inst : object , recurse : bool = ..., filter : Optional [FilterType ] = ..., dict_factory : Type [_M ] = ..., retain_collection_types : bool = ...) -> _M : ...
57
- def astuple (inst : object , recurse : bool = ..., filter : Optional [FilterType ] = ..., tuple_factory : Type [_I ] = ..., retain_collection_types : bool = ...) -> _I : ...
54
+ # def asdict(inst: Any , recurse: bool = ..., filter: Optional[_FilterType ] = ..., dict_factory: Type[_M] = dict, retain_collection_types: bool = ...) -> _M[str, Any]: ...
55
+ # def astuple(inst: Any , recurse: bool = ..., filter: Optional[_FilterType ] = ..., tuple_factory: Type[_I] = tuple, retain_collection_types: bool = ...) -> _I: ...
56
+ def asdict (inst : Any , recurse : bool = ..., filter : Optional [_FilterType ] = ..., dict_factory : Type [_M ] = ..., retain_collection_types : bool = ...) -> _M : ...
57
+ def astuple (inst : Any , recurse : bool = ..., filter : Optional [_FilterType ] = ..., tuple_factory : Type [_I ] = ..., retain_collection_types : bool = ...) -> _I : ...
58
58
def has (cls : type ) -> bool : ...
59
59
def assoc (inst : _T , ** changes ) -> _T : ...
60
60
def evolve (inst : _T , ** changes ) -> _T : ...
0 commit comments