From e56adddc48367457975d9b26923409192c367297 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Fri, 3 Apr 2020 17:23:05 -0700 Subject: [PATCH] dataclasses: change hash to unsafe_hash, add a minor overload (#3892) Co-authored-by: hauntsaninja <> --- stdlib/3.7/dataclasses.pyi | 5 ++++- tests/stubtest_whitelists/py37.txt | 2 -- tests/stubtest_whitelists/py38.txt | 1 - third_party/3/dataclasses.pyi | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stdlib/3.7/dataclasses.pyi b/stdlib/3.7/dataclasses.pyi index 77da4809c..e0885932d 100644 --- a/stdlib/3.7/dataclasses.pyi +++ b/stdlib/3.7/dataclasses.pyi @@ -20,6 +20,9 @@ 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]]: ... @@ -65,7 +68,7 @@ class InitVar(Generic[_T]): ... 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 = ..., hash: bool = ..., + init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...) -> type: ... def replace(obj: _T, **changes: Any) -> _T: ... diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index e4982a030..e90bf3013 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -37,9 +37,7 @@ contextvars.Context.__init__ contextvars.Context.get copy.PyStringMap ctypes.CDLL.__init__ -dataclasses.dataclass dataclasses.field -dataclasses.make_dataclass email.message.MIMEPart.as_string enum.Enum._generate_next_value_ gettext.NullTranslations.npgettext diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index 95be7c1b7..c8ce2a5b2 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -89,7 +89,6 @@ contextvars.ContextVar.set copy.PyStringMap dataclasses.dataclass dataclasses.field -dataclasses.make_dataclass dataclasses.replace decimal.Decimal.from_float decimal.setcontext diff --git a/third_party/3/dataclasses.pyi b/third_party/3/dataclasses.pyi index 77da4809c..e0885932d 100644 --- a/third_party/3/dataclasses.pyi +++ b/third_party/3/dataclasses.pyi @@ -20,6 +20,9 @@ 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]]: ... @@ -65,7 +68,7 @@ class InitVar(Generic[_T]): ... 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 = ..., hash: bool = ..., + init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ...) -> type: ... def replace(obj: _T, **changes: Any) -> _T: ...