Skip to content

Commit b26ca6d

Browse files
committed
Preliminary implementation of stdlib/3.7/dataclasses.pyi.
1 parent a5429d2 commit b26ca6d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

stdlib/3.7/dataclasses.pyi

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from typing import overload, Any, Callable, Dict, Generic, Iterable, Mapping, Optional, Tuple, Type, TypeVar, Union
2+
3+
4+
_T = TypeVar('_T')
5+
6+
_DictType = TypeVar('_DictType', bound=dict)
7+
_TupleType = TypeVar('_TupleType', bound=tuple)
8+
9+
class _MISSING_TYPE: ...
10+
11+
class _InitVarMeta(type): ...
12+
13+
def asdict(obj: Any, *, dict_factory: _DictType = ...) -> _DictType: ...
14+
15+
def astuple(obj: Any, *, tuple_factory: _TupleType = ...) -> _TupleType: ...
16+
17+
@overload
18+
def dataclass(_cls: Type[_T]) -> Type[_T]: ...
19+
20+
@overload
21+
def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ...,
22+
unsafe_hash: bool = ..., frozen: bool = ...) -> Callable[[Type[_T]], Type[_T]]: ...
23+
24+
25+
class Field(Generic[_T]):
26+
name: str
27+
type: Type[_T]
28+
default: _T
29+
default_factory: Callable[[], _T]
30+
repr: bool
31+
hash: Optional[bool]
32+
init: bool
33+
compare: bool
34+
metadata: Optional[Mapping[str, Any]]
35+
36+
37+
def field(*, default: Union[_T, _MISSING_TYPE] = ..., default_factory: Union[Callable[[], _T], _MISSING_TYPE] = ...,
38+
init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ...,
39+
metadata: Optional[Mapping[str, Any]] = ...) -> Field: ...
40+
41+
def fields(class_or_instance: Type) -> Tuple[Field, ...]: ...
42+
43+
def is_dataclass(obj: Any) -> bool: ...
44+
45+
class FrozenInstanceError(AttributeError): ...
46+
47+
class InitVar(metaclass=_InitVarMeta): ...
48+
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] = ...,
51+
init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., hash: bool = ..., frozen: bool = ...): ...
52+
53+
def replace(obj: _T, **changes: Any) -> _T: ...

0 commit comments

Comments
 (0)