mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-20 10:51:15 +08:00
dataclasses: various fixes (#4937)
This commit is contained in:
@@ -17,14 +17,27 @@ def asdict(obj: Any, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T]) ->
|
||||
def astuple(obj: Any) -> Tuple[Any, ...]: ...
|
||||
@overload
|
||||
def astuple(obj: Any, *, tuple_factory: Callable[[List[Any]], _T]) -> _T: ...
|
||||
@overload
|
||||
def dataclass(_cls: Type[_T]) -> Type[_T]: ...
|
||||
@overload
|
||||
def dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
|
||||
@overload
|
||||
def dataclass(
|
||||
*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
|
||||
) -> Callable[[Type[_T]], Type[_T]]: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
# cls argument is now positional-only
|
||||
@overload
|
||||
def dataclass(__cls: Type[_T]) -> Type[_T]: ...
|
||||
@overload
|
||||
def dataclass(__cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
|
||||
@overload
|
||||
def dataclass(
|
||||
*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
|
||||
) -> Callable[[Type[_T]], Type[_T]]: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
def dataclass(_cls: Type[_T]) -> Type[_T]: ...
|
||||
@overload
|
||||
def dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]]: ...
|
||||
@overload
|
||||
def dataclass(
|
||||
*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...
|
||||
) -> Callable[[Type[_T]], Type[_T]]: ...
|
||||
|
||||
class Field(Generic[_T]):
|
||||
name: str
|
||||
@@ -36,6 +49,16 @@ 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, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
@@ -76,8 +99,13 @@ def is_dataclass(obj: Any) -> bool: ...
|
||||
class FrozenInstanceError(AttributeError): ...
|
||||
|
||||
class InitVar(Generic[_T]):
|
||||
type: Type[_T]
|
||||
def __init__(self, type: Type[_T]) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, type: Any) -> GenericAlias: ...
|
||||
@overload
|
||||
def __class_getitem__(cls, type: Type[_T]) -> InitVar[_T]: ...
|
||||
@overload
|
||||
def __class_getitem__(cls, type: Any) -> InitVar[Any]: ...
|
||||
|
||||
def make_dataclass(
|
||||
cls_name: str,
|
||||
@@ -92,4 +120,4 @@ def make_dataclass(
|
||||
unsafe_hash: bool = ...,
|
||||
frozen: bool = ...,
|
||||
) -> type: ...
|
||||
def replace(obj: _T, **changes: Any) -> _T: ...
|
||||
def replace(__obj: _T, **changes: Any) -> _T: ...
|
||||
|
||||
@@ -37,6 +37,7 @@ copy.PyStringMap
|
||||
dataclasses.Field.__init__
|
||||
dataclasses.InitVar.__init__
|
||||
dataclasses.field
|
||||
dataclasses.InitVar.__class_getitem__ # stubtest bug. doesn't do the right thing with overload + implicit classmethod __class_getitem__
|
||||
dummy_threading
|
||||
email.message.MIMEPart.as_string
|
||||
enum.Enum._generate_next_value_
|
||||
|
||||
Reference in New Issue
Block a user