@@ -3,16 +3,18 @@ from typing import overload, Any, Callable, Dict, Generic, Iterable, Mapping, Op
3
3
4
4
_T = TypeVar ('_T' )
5
5
6
- _DictType = TypeVar ( '_DictType' , bound = dict )
7
- _TupleType = TypeVar ( '_TupleType' , bound = tuple )
6
+ _DictFactory = Callable [ List [ Tuple [ str , Any ]], _T ]
7
+ _TupleFactory = Callable [ List [ Any ], _T ]
8
8
9
9
class _MISSING_TYPE : ...
10
+ MISSING : _MISSING_TYPE
10
11
11
12
class _InitVarMeta (type ): ...
12
13
13
- def asdict (obj : Any , * , dict_factory : _DictType = ...) -> _DictType : ...
14
+ def asdict (obj : Any , * , dict_factory : _DictFactory = ...) -> _T : ...
15
+
16
+ def astuple (obj : Any , * , tuple_factory : _TupleFactory = ...) -> _T : ...
14
17
15
- def astuple (obj : Any , * , tuple_factory : _TupleType = ...) -> _TupleType : ...
16
18
17
19
@overload
18
20
def dataclass (_cls : Type [_T ]) -> Type [_T ]: ...
@@ -34,20 +36,32 @@ class Field(Generic[_T]):
34
36
metadata : Optional [Mapping [str , Any ]]
35
37
36
38
37
- def field (* , default : Union [_T , _MISSING_TYPE ] = ..., default_factory : Union [Callable [[], _T ], _MISSING_TYPE ] = ...,
39
+ @overload # `default` and `default_factory` are optional and mutually exclusive.
40
+ def field (* , default : _T = ..., default_factory : _MISSING_TYPE = ...,
41
+ init : bool = ..., repr : bool = ..., hash : Optional [bool ] = ..., compare : bool = ...,
42
+ metadata : Optional [Mapping [str , Any ]] = ...) -> Field [_T ]: ...
43
+
44
+ @overload
45
+ def field (* , default : _MISSING_TYPE = ..., default_factory : Callable [[], _T ] = ...,
46
+ init : bool = ..., repr : bool = ..., hash : Optional [bool ] = ..., compare : bool = ...,
47
+ metadata : Optional [Mapping [str , Any ]] = ...) -> Field [_T ]: ...
48
+
49
+ @overload
50
+ def field (* , default : _MISSING_TYPE = ..., default_factory : _MISSING_TYPE = ...,
38
51
init : bool = ..., repr : bool = ..., hash : Optional [bool ] = ..., compare : bool = ...,
39
- metadata : Optional [Mapping [str , Any ]] = ...) -> Field : ...
52
+ metadata : Optional [Mapping [str , Any ]] = ...) -> Field [Any ]: ...
53
+
40
54
41
- def fields (class_or_instance : Type ) -> Tuple [Field , ...]: ...
55
+ def fields (class_or_instance : Any ) -> Tuple [Field [ Any ] , ...]: ...
42
56
43
57
def is_dataclass (obj : Any ) -> bool : ...
44
58
45
59
class FrozenInstanceError (AttributeError ): ...
46
60
47
61
class InitVar (metaclass = _InitVarMeta ): ...
48
62
49
- def make_dataclass (cls_name : str , fields : Iterable [Union [str , Tuple [str , type ], Tuple [str , type , Field ]]], * ,
50
- bases : Tuple [type , ...] = ..., namespace : Dict [str , Any ] = ...,
63
+ def make_dataclass (cls_name : str , fields : Iterable [Union [str , Tuple [str , type ], Tuple [str , type , Field [ Any ] ]]], * ,
64
+ bases : Tuple [type , ...] = ..., namespace : Optional [ Dict [str , Any ] ] = ...,
51
65
init : bool = ..., repr : bool = ..., eq : bool = ..., order : bool = ..., hash : bool = ..., frozen : bool = ...): ...
52
66
53
67
def replace (obj : _T , ** changes : Any ) -> _T : ...
0 commit comments