Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b7df3b

Browse files
dataclasses: fix and sort stubtest complaints (#7888)
1 parent 4220712 commit 0b7df3b

6 files changed

Lines changed: 37 additions & 9 deletions

File tree

stdlib/dataclasses.pyi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,26 @@ class InitVar(Generic[_T]):
240240
@overload
241241
def __class_getitem__(cls, type: Any) -> InitVar[Any]: ...
242242

243-
if sys.version_info >= (3, 10):
243+
if sys.version_info >= (3, 11):
244+
def make_dataclass(
245+
cls_name: str,
246+
fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]],
247+
*,
248+
bases: tuple[type, ...] = ...,
249+
namespace: dict[str, Any] | None = ...,
250+
init: bool = ...,
251+
repr: bool = ...,
252+
eq: bool = ...,
253+
order: bool = ...,
254+
unsafe_hash: bool = ...,
255+
frozen: bool = ...,
256+
match_args: bool = ...,
257+
kw_only: bool = ...,
258+
slots: bool = ...,
259+
weakref_slot: bool = ...,
260+
) -> type: ...
261+
262+
elif sys.version_info >= (3, 10):
244263
def make_dataclass(
245264
cls_name: str,
246265
fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]],

tests/stubtest_allowlists/py310.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ builtins.float.__setformat__ # Internal method for CPython test suite
1414
builtins.property.__set_name__ # Doesn't actually exist
1515
contextlib.AbstractAsyncContextManager.__class_getitem__
1616
contextlib.AbstractContextManager.__class_getitem__
17-
dataclasses.field
18-
dataclasses.KW_ONLY
1917
enum.Enum._generate_next_value_
2018
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
2119
gettext.install
@@ -194,3 +192,7 @@ ast.ImportFrom.level # None on the class, but never None on instances
194192
# These enums derive from (str, Enum). See comment in py3_common.txt
195193
pstats.SortKey.__new__
196194
tkinter.EventType.__new__
195+
196+
# White lies around defaults
197+
dataclasses.field
198+
dataclasses.KW_ONLY

tests/stubtest_allowlists/py311.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ concurrent.futures.process._process_worker
4141
concurrent.futures.process._sendback_result
4242
configparser.LegacyInterpolation.__init__
4343
contextvars.Context.__init__
44-
dataclasses.KW_ONLY
45-
dataclasses.field
46-
dataclasses.make_dataclass
4744
distutils.dist.DistributionMetadata.set_classifiers
4845
distutils.dist.DistributionMetadata.set_keywords
4946
distutils.dist.DistributionMetadata.set_platforms
@@ -264,6 +261,10 @@ typing._TypedDict.setdefault
264261
typing._TypedDict.update
265262
typing._TypedDict.values
266263

264+
# White lies around defaults
265+
dataclasses.KW_ONLY
266+
dataclasses.field
267+
267268
# https://github.com/python/mypy/issues/12819 (... in runtime default)
268269
wsgiref.types.InputStream.read
269270
wsgiref.types.InputStream.readline

tests/stubtest_allowlists/py37.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ collections.Callable
2727
collections.Mapping.__reversed__ # Set to None at runtime for a better error message
2828
collections.UserString.maketrans
2929
contextvars.ContextVar.get
30-
dataclasses.field
3130
distutils.command.bdist_wininst # see #6523
3231
dummy_threading.Condition.acquire
3332
dummy_threading.Condition.release
@@ -171,3 +170,6 @@ queue.SimpleQueue.__init__
171170

172171
pyexpat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args
173172
xml.parsers.expat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args
173+
174+
# White lies around defaults
175+
dataclasses.field

tests/stubtest_allowlists/py38.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ collections.ItemsView.__reversed__
3232
collections.KeysView.__reversed__
3333
collections.ValuesView.__reversed__
3434
collections.Mapping.__reversed__ # Set to None at runtime for a better error message
35-
dataclasses.field
3635
distutils.command.bdist_wininst # see #6523
3736
dummy_threading.Condition.acquire
3837
dummy_threading.Condition.release
@@ -195,3 +194,6 @@ queue.SimpleQueue.__init__
195194

196195
uuid.getnode # undocumented, unused parameter getters that was later removed
197196
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
197+
198+
# White lies around defaults
199+
dataclasses.field

tests/stubtest_allowlists/py39.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ collections.KeysView.__reversed__
3232
collections.ValuesView.__reversed__
3333
contextlib.AbstractAsyncContextManager.__class_getitem__
3434
contextlib.AbstractContextManager.__class_getitem__
35-
dataclasses.field
3635
distutils.command.bdist_wininst # see #6523
3736
enum.Enum._generate_next_value_
3837
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
195194

196195
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
197196
os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem
197+
198+
# White lies around defaults
199+
dataclasses.field

0 commit comments

Comments
 (0)