From 0b7df3b2aa2e8d7d9a2ac88c8358403cbc2f733a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 19 May 2022 19:13:22 -0700 Subject: [PATCH] dataclasses: fix and sort stubtest complaints (#7888) --- stdlib/dataclasses.pyi | 21 ++++++++++++++++++++- tests/stubtest_allowlists/py310.txt | 6 ++++-- tests/stubtest_allowlists/py311.txt | 7 ++++--- tests/stubtest_allowlists/py37.txt | 4 +++- tests/stubtest_allowlists/py38.txt | 4 +++- tests/stubtest_allowlists/py39.txt | 4 +++- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/stdlib/dataclasses.pyi b/stdlib/dataclasses.pyi index 1cbf998dd..013276479 100644 --- a/stdlib/dataclasses.pyi +++ b/stdlib/dataclasses.pyi @@ -240,7 +240,26 @@ class InitVar(Generic[_T]): @overload def __class_getitem__(cls, type: Any) -> InitVar[Any]: ... -if sys.version_info >= (3, 10): +if sys.version_info >= (3, 11): + def make_dataclass( + cls_name: str, + fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], + *, + bases: tuple[type, ...] = ..., + namespace: dict[str, Any] | None = ..., + init: bool = ..., + repr: bool = ..., + eq: bool = ..., + order: bool = ..., + unsafe_hash: bool = ..., + frozen: bool = ..., + match_args: bool = ..., + kw_only: bool = ..., + slots: bool = ..., + weakref_slot: bool = ..., + ) -> type: ... + +elif sys.version_info >= (3, 10): def make_dataclass( cls_name: str, fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 7f836123f..ab2da8eee 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -14,8 +14,6 @@ builtins.float.__setformat__ # Internal method for CPython test suite builtins.property.__set_name__ # Doesn't actually exist contextlib.AbstractAsyncContextManager.__class_getitem__ contextlib.AbstractContextManager.__class_getitem__ -dataclasses.field -dataclasses.KW_ONLY enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve gettext.install @@ -194,3 +192,7 @@ ast.ImportFrom.level # None on the class, but never None on instances # These enums derive from (str, Enum). See comment in py3_common.txt pstats.SortKey.__new__ tkinter.EventType.__new__ + +# White lies around defaults +dataclasses.field +dataclasses.KW_ONLY diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 7b1c7625b..b664146e8 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -41,9 +41,6 @@ concurrent.futures.process._process_worker concurrent.futures.process._sendback_result configparser.LegacyInterpolation.__init__ contextvars.Context.__init__ -dataclasses.KW_ONLY -dataclasses.field -dataclasses.make_dataclass distutils.dist.DistributionMetadata.set_classifiers distutils.dist.DistributionMetadata.set_keywords distutils.dist.DistributionMetadata.set_platforms @@ -264,6 +261,10 @@ typing._TypedDict.setdefault typing._TypedDict.update typing._TypedDict.values +# White lies around defaults +dataclasses.KW_ONLY +dataclasses.field + # https://github.com/python/mypy/issues/12819 (... in runtime default) wsgiref.types.InputStream.read wsgiref.types.InputStream.readline diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index 6db13c226..c5aac0550 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -27,7 +27,6 @@ collections.Callable collections.Mapping.__reversed__ # Set to None at runtime for a better error message collections.UserString.maketrans contextvars.ContextVar.get -dataclasses.field distutils.command.bdist_wininst # see #6523 dummy_threading.Condition.acquire dummy_threading.Condition.release @@ -171,3 +170,6 @@ queue.SimpleQueue.__init__ pyexpat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args xml.parsers.expat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args + +# White lies around defaults +dataclasses.field diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index b13fa07e4..05b9a604c 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -32,7 +32,6 @@ collections.ItemsView.__reversed__ collections.KeysView.__reversed__ collections.ValuesView.__reversed__ collections.Mapping.__reversed__ # Set to None at runtime for a better error message -dataclasses.field distutils.command.bdist_wininst # see #6523 dummy_threading.Condition.acquire dummy_threading.Condition.release @@ -195,3 +194,6 @@ queue.SimpleQueue.__init__ uuid.getnode # undocumented, unused parameter getters that was later removed types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime + +# White lies around defaults +dataclasses.field diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index d607f8db8..6b269829c 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -32,7 +32,6 @@ collections.KeysView.__reversed__ collections.ValuesView.__reversed__ contextlib.AbstractAsyncContextManager.__class_getitem__ contextlib.AbstractContextManager.__class_getitem__ -dataclasses.field distutils.command.bdist_wininst # see #6523 enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve @@ -195,3 +194,6 @@ ast.ImportFrom.level # None on the class, but never None on instances ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem + +# White lies around defaults +dataclasses.field