mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
dataclasses: update for py310 (#5525)
This commit is contained in:
@@ -10,6 +10,10 @@ class _MISSING_TYPE: ...
|
||||
|
||||
MISSING: _MISSING_TYPE
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
class _KW_ONLY_TYPE: ...
|
||||
KW_ONLY: _KW_ONLY_TYPE
|
||||
|
||||
@overload
|
||||
def asdict(obj: Any) -> Dict[str, Any]: ...
|
||||
@overload
|
||||
@@ -20,7 +24,6 @@ def astuple(obj: Any) -> Tuple[Any, ...]: ...
|
||||
def astuple(obj: Any, *, tuple_factory: Callable[[List[Any]], _T]) -> _T: ...
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
# Added match_args
|
||||
@overload
|
||||
def dataclass(__cls: Type[_T]) -> Type[_T]: ...
|
||||
@overload
|
||||
@@ -35,6 +38,8 @@ if sys.version_info >= (3, 10):
|
||||
unsafe_hash: bool = ...,
|
||||
frozen: bool = ...,
|
||||
match_args: bool = ...,
|
||||
kw_only: bool = ...,
|
||||
slots: bool = ...,
|
||||
) -> Callable[[Type[_T]], Type[_T]]: ...
|
||||
|
||||
elif sys.version_info >= (3, 8):
|
||||
@@ -68,50 +73,100 @@ class Field(Generic[_T]):
|
||||
init: bool
|
||||
compare: bool
|
||||
metadata: Mapping[str, Any]
|
||||
def __init__(
|
||||
self,
|
||||
default: _T,
|
||||
default_factory: Callable[[], _T],
|
||||
init: bool,
|
||||
repr: bool,
|
||||
hash: Optional[bool],
|
||||
compare: bool,
|
||||
metadata: Mapping[str, Any],
|
||||
) -> None: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
kw_only: bool
|
||||
def __init__(
|
||||
self,
|
||||
default: _T,
|
||||
default_factory: Callable[[], _T],
|
||||
init: bool,
|
||||
repr: bool,
|
||||
hash: Optional[bool],
|
||||
compare: bool,
|
||||
metadata: Mapping[str, Any],
|
||||
kw_only: bool,
|
||||
) -> None: ...
|
||||
else:
|
||||
def __init__(
|
||||
self,
|
||||
default: _T,
|
||||
default_factory: Callable[[], _T],
|
||||
init: bool,
|
||||
repr: bool,
|
||||
hash: Optional[bool],
|
||||
compare: bool,
|
||||
metadata: Mapping[str, Any],
|
||||
) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
# NOTE: Actual return type is 'Field[_T]', but we want to help type checkers
|
||||
# to understand the magic that happens at runtime.
|
||||
@overload # `default` and `default_factory` are optional and mutually exclusive.
|
||||
def field(
|
||||
*,
|
||||
default: _T,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
) -> _T: ...
|
||||
@overload
|
||||
def field(
|
||||
*,
|
||||
default_factory: Callable[[], _T],
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
) -> _T: ...
|
||||
@overload
|
||||
def field(
|
||||
*,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
) -> Any: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@overload # `default` and `default_factory` are optional and mutually exclusive.
|
||||
def field(
|
||||
*,
|
||||
default: _T,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
kw_only: bool = ...,
|
||||
) -> _T: ...
|
||||
@overload
|
||||
def field(
|
||||
*,
|
||||
default_factory: Callable[[], _T],
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
kw_only: bool = ...,
|
||||
) -> _T: ...
|
||||
@overload
|
||||
def field(
|
||||
*,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
kw_only: bool = ...,
|
||||
) -> Any: ...
|
||||
|
||||
else:
|
||||
@overload # `default` and `default_factory` are optional and mutually exclusive.
|
||||
def field(
|
||||
*,
|
||||
default: _T,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
) -> _T: ...
|
||||
@overload
|
||||
def field(
|
||||
*,
|
||||
default_factory: Callable[[], _T],
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
) -> _T: ...
|
||||
@overload
|
||||
def field(
|
||||
*,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
hash: Optional[bool] = ...,
|
||||
compare: bool = ...,
|
||||
metadata: Optional[Mapping[str, Any]] = ...,
|
||||
) -> Any: ...
|
||||
|
||||
def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ...
|
||||
def is_dataclass(obj: Any) -> bool: ...
|
||||
|
||||
@@ -126,17 +181,36 @@ class InitVar(Generic[_T]):
|
||||
@overload
|
||||
def __class_getitem__(cls, type: Any) -> InitVar[Any]: ...
|
||||
|
||||
def make_dataclass(
|
||||
cls_name: str,
|
||||
fields: Iterable[Union[str, Tuple[str, type], Tuple[str, type, Field[Any]]]],
|
||||
*,
|
||||
bases: Tuple[type, ...] = ...,
|
||||
namespace: Optional[Dict[str, Any]] = ...,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
eq: bool = ...,
|
||||
order: bool = ...,
|
||||
unsafe_hash: bool = ...,
|
||||
frozen: bool = ...,
|
||||
) -> type: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
def make_dataclass(
|
||||
cls_name: str,
|
||||
fields: Iterable[Union[str, Tuple[str, type], Tuple[str, type, Field[Any]]]],
|
||||
*,
|
||||
bases: Tuple[type, ...] = ...,
|
||||
namespace: Optional[Dict[str, Any]] = ...,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
eq: bool = ...,
|
||||
order: bool = ...,
|
||||
unsafe_hash: bool = ...,
|
||||
frozen: bool = ...,
|
||||
match_args: bool = ...,
|
||||
slots: bool = ...,
|
||||
) -> type: ...
|
||||
|
||||
else:
|
||||
def make_dataclass(
|
||||
cls_name: str,
|
||||
fields: Iterable[Union[str, Tuple[str, type], Tuple[str, type, Field[Any]]]],
|
||||
*,
|
||||
bases: Tuple[type, ...] = ...,
|
||||
namespace: Optional[Dict[str, Any]] = ...,
|
||||
init: bool = ...,
|
||||
repr: bool = ...,
|
||||
eq: bool = ...,
|
||||
order: bool = ...,
|
||||
unsafe_hash: bool = ...,
|
||||
frozen: bool = ...,
|
||||
) -> type: ...
|
||||
|
||||
def replace(__obj: _T, **changes: Any) -> _T: ...
|
||||
|
||||
Reference in New Issue
Block a user