1
- from typing import Any , Callable , Dict , Iterable , List , Optional , Mapping , Tuple , Type , TypeVar , Union , overload
1
+ from typing import Any , Callable , Dict , Generic , Iterable , List , Optional , Mapping , Tuple , Type , TypeVar , Union , overload
2
2
from . import exceptions
3
3
from . import filters
4
4
from . import converters
5
5
from . import validators
6
6
7
7
# typing --
8
8
9
- C = TypeVar ('C' , bound = type )
10
- M = TypeVar ('M ' , bound = Mapping )
11
- T = TypeVar ('T ' , bound = tuple )
12
- I = TypeVar ('I' )
9
+ _T = TypeVar ('_T' )
10
+ _C = TypeVar ('_C ' , bound = type )
11
+ _M = TypeVar ('_M ' , bound = Mapping )
12
+ _TT = TypeVar ('_TT' , bound = tuple )
13
13
14
14
ValidatorType = Callable [[object , 'Attribute' , Any ], Any ]
15
15
ConverterType = Callable [[Any ], Any ]
@@ -21,41 +21,41 @@ class _CountingAttr: ...
21
21
22
22
NOTHING : object
23
23
24
+ class Factory (Generic [_T ]):
25
+ factory : Union [Callable [[], _T ], Callable [[object ], _T ]]
26
+ takes_self : bool
27
+ def __init__ (self , factory : Union [Callable [[], _T ], Callable [[object ], _T ]], takes_self : bool = ...) -> None : ...
28
+
24
29
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
+ __slots__ = ("name" , "default" , "validator" , "repr" , "cmp" , "hash" , "init" , "convert" , "metadata" , "type" )
31
+ 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 : ...
30
32
31
- # NOTE: the stub for `attr` returns Any so that static analysis passes when used in the form: x : int = attr()
33
+ # NOTE: this overload for `attr` returns Any so that static analysis passes when used in the form: x : int = attr()
34
+ @overload
32
35
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 : ...
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 = ..., type : Union [Type [_T ], Factory [_T ]] = ...) -> _T : ...
33
38
34
39
@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 : ...
40
+ 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
41
@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 ]: ...
42
+ 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
43
39
44
def fields (cls : type ) -> Tuple [Attribute , ...]: ...
40
45
def validate (inst : object ) -> None : ...
41
46
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
47
def make_class (name , attrs : Union [List [_CountingAttr ], Dict [str , _CountingAttr ]], bases : Tuple [type , ...] = ..., ** attributes_arguments ) -> type : ...
48
48
49
49
def and_ (* validators : Iterable [ValidatorType ]) -> ValidatorType : ...
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 : 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 : ...
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 ], _TT ] = ..., retain_collection_types : bool = ...) -> _TT : ...
56
56
def has (cls : type ) -> bool : ...
57
- def assoc (inst : I , ** changes ) -> I : ...
58
- def evolve (inst : I , ** changes ) -> I : ...
57
+ def assoc (inst : _T , ** changes ) -> _T : ...
58
+ def evolve (inst : _T , ** changes ) -> _T : ...
59
59
60
60
# _config --
61
61
0 commit comments