Skip to content

Commit 66226ab

Browse files
gwkJelleZijlstra
authored andcommitted
Preliminary implementation of stdlib/3.7/dataclasses.pyi. (#1944)
1 parent 351d019 commit 66226ab

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

stdlib/3.7/dataclasses.pyi

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from typing import overload, Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, Type, TypeVar, Union
2+
3+
4+
_T = TypeVar('_T')
5+
6+
class _MISSING_TYPE: ...
7+
MISSING: _MISSING_TYPE
8+
9+
def asdict(obj: Any, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T] = ...) -> _T: ...
10+
11+
def astuple(obj: Any, *, tuple_factory: Callable[[List[Any]], _T] = ...) -> _T: ...
12+
13+
14+
@overload
15+
def dataclass(_cls: Type[_T]) -> Type[_T]: ...
16+
17+
@overload
18+
def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ...,
19+
unsafe_hash: bool = ..., frozen: bool = ...) -> Callable[[Type[_T]], Type[_T]]: ...
20+
21+
22+
class Field(Generic[_T]):
23+
name: str
24+
type: Type[_T]
25+
default: _T
26+
default_factory: Callable[[], _T]
27+
repr: bool
28+
hash: Optional[bool]
29+
init: bool
30+
compare: bool
31+
metadata: Optional[Mapping[str, Any]]
32+
33+
34+
@overload # `default` and `default_factory` are optional and mutually exclusive.
35+
def field(*, default: _T,
36+
init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ...,
37+
metadata: Optional[Mapping[str, Any]] = ...) -> Field[_T]: ...
38+
39+
@overload
40+
def field(*, default_factory: Callable[[], _T],
41+
init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ...,
42+
metadata: Optional[Mapping[str, Any]] = ...) -> Field[_T]: ...
43+
44+
@overload
45+
def field(*,
46+
init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ...,
47+
metadata: Optional[Mapping[str, Any]] = ...) -> Field[Any]: ...
48+
49+
50+
def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ...
51+
52+
def is_dataclass(obj: Any) -> bool: ...
53+
54+
class FrozenInstanceError(AttributeError): ...
55+
56+
class InitVar(Generic[_T]): ...
57+
58+
def make_dataclass(cls_name: str, fields: Iterable[Union[str, Tuple[str, type], Tuple[str, type, Field[Any]]]], *,
59+
bases: Tuple[type, ...] = ..., namespace: Optional[Dict[str, Any]] = ...,
60+
init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., hash: bool = ..., frozen: bool = ...): ...
61+
62+
def replace(obj: _T, **changes: Any) -> _T: ...

0 commit comments

Comments
 (0)