Skip to content

Commit 9306d42

Browse files
committed
Run stubtest for Python 3.12
1 parent d5555b1 commit 9306d42

File tree

6 files changed

+178
-4
lines changed

6 files changed

+178
-4
lines changed

.github/workflows/stubtest_stdlib.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
matrix:
3333
# tkinter doesn't import on macOS 12
3434
os: ["ubuntu-latest", "windows-latest", "macos-11"]
35-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
35+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
3636
fail-fast: false
3737

3838
steps:

stdlib/builtins.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ from typing import ( # noqa: Y022
5353
overload,
5454
type_check_only,
5555
)
56-
from typing_extensions import (
56+
from typing_extensions import ( # type: ignore
5757
Concatenate,
5858
Literal,
5959
LiteralString,
@@ -465,7 +465,7 @@ class str(Sequence[str]):
465465
@overload
466466
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
467467
@overload
468-
def format(self, *args: object, **kwargs: object) -> str: ...
468+
def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore
469469
def format_map(self, map: _FormatMapMapping) -> str: ...
470470
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
471471
def isalnum(self) -> bool: ...
@@ -595,7 +595,7 @@ class str(Sequence[str]):
595595
@overload
596596
def __mod__(self: LiteralString, __value: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
597597
@overload
598-
def __mod__(self, __value: Any) -> str: ...
598+
def __mod__(self, __value: Any) -> str: ... # type: ignore
599599
@overload
600600
def __mul__(self: LiteralString, __value: SupportsIndex) -> LiteralString: ...
601601
@overload
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
_?curses.color_pair
2+
xxlimited.Xxo.x_exports
3+
4+
# Exists at runtime, missing from stub
5+
socket.TCP_CONNECTION_INFO
6+
7+
(dbm.gnu)?
8+
(locale.bind_textdomain_codeset)?
9+
(locale.bindtextdomain)?
10+
(locale.dcgettext)
11+
(locale.dgettext)?
12+
(locale.gettext)?
13+
(locale.textdomain)?

tests/stubtest_allowlists/py312.txt

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
_collections_abc.AsyncGenerator.ag_await
2+
_collections_abc.AsyncGenerator.ag_code
3+
_collections_abc.AsyncGenerator.ag_frame
4+
_collections_abc.AsyncGenerator.ag_running
5+
_collections_abc.AsyncIterable.__class_getitem__
6+
_collections_abc.Awaitable.__class_getitem__
7+
_collections_abc.Container.__class_getitem__
8+
_collections_abc.ItemsView.__reversed__
9+
_collections_abc.Iterable.__class_getitem__
10+
_collections_abc.KeysView.__reversed__
11+
_collections_abc.MappingView.__class_getitem__
12+
_collections_abc.ValuesView.__reversed__
13+
_csv.Reader
14+
_csv.Writer
15+
argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group
16+
configparser.LegacyInterpolation.__init__
17+
enum.Enum.__init__
18+
# TODO: The stub for enum.auto is nothing like the implementation
19+
enum.auto.__init__
20+
enum.auto.value
21+
fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve
22+
ftplib.FTP.trust_server_pasv_ipv4_address
23+
functools.cached_property.__set__ # Stub is a white lie; see comments in the stub
24+
functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically
25+
ipaddress.IPv4Interface.hostmask
26+
ipaddress.IPv6Interface.hostmask
27+
ipaddress._BaseNetwork.broadcast_address
28+
ipaddress._BaseNetwork.hostmask
29+
multiprocessing.managers.SharedMemoryServer.create
30+
multiprocessing.managers.SharedMemoryServer.list_segments
31+
multiprocessing.managers.SharedMemoryServer.public
32+
multiprocessing.managers.SharedMemoryServer.release_segment
33+
multiprocessing.managers.SharedMemoryServer.shutdown
34+
multiprocessing.managers.SharedMemoryServer.track_segment
35+
multiprocessing.spawn._main
36+
# platform.uname_result's processor field is now dynamically made to exist
37+
platform.uname_result.__match_args__
38+
platform.uname_result.__new__
39+
platform.uname_result.processor
40+
queue.SimpleQueue.__init__
41+
sys.UnraisableHookArgs # Not exported from sys
42+
tkinter._VersionInfoType.__doc__
43+
typing.NewType.__call__
44+
typing.NewType.__mro_entries__
45+
weakref.WeakValueDictionary.update
46+
47+
# Runtime has *args, **kwargs, but will error if any are supplied
48+
unittest.TestCase.__init_subclass__
49+
unittest.case.TestCase.__init_subclass__
50+
51+
# ==========
52+
# Related to positional-only arguments
53+
# ==========
54+
55+
# These are not positional-only at runtime, but we treat them
56+
# as positional-only to match dict.
57+
_collections_abc.MutableMapping.pop
58+
_collections_abc.MutableMapping.setdefault
59+
60+
# typing.IO uses positional-or-keyword arguments, but in the stubs we prefer
61+
# to mark these as positional-only for compatibility with existing sub-classes.
62+
typing.BinaryIO.write
63+
typing.IO.read
64+
typing.IO.readline
65+
typing.IO.readlines
66+
typing.IO.seek
67+
typing.IO.truncate
68+
typing.IO.write
69+
typing.IO.writelines
70+
71+
# positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib
72+
_collections_abc.Coroutine.send
73+
_collections_abc.Coroutine.throw
74+
_collections_abc.Generator.send
75+
_collections_abc.Generator.throw
76+
77+
# typing.SupportsRound.__round__ # pos-or-kw at runtime, but we pretend it's pos-only in the stub so that e.g. float.__round__ satisfies the interface
78+
types.DynamicClassAttribute..* # In the stub we pretend it's an alias for property, but it has positional-only differences
79+
80+
# These three have a pos-or-keyword first parameter at runtime, but deliberately have a pos-only first parameter in the stub. #6812
81+
posixpath.join
82+
ntpath.join
83+
os.path.join
84+
85+
# ==========
86+
# Allowlist entries that cannot or should not be fixed
87+
# ==========
88+
89+
_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also.
90+
_weakref.ProxyType.__reversed__ # Doesn't really exist
91+
builtins.property.__set_name__ # Doesn't actually exist
92+
hmac.new # Stub is a white lie; see comments in the stub
93+
http.HTTPMethod.description # mutable instance attribute at runtime but we pretend it's a property
94+
pickle.Pickler.reducer_override # implemented in C pickler
95+
types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392
96+
types.GenericAlias.__getattr__
97+
types.GenericAlias.__mro_entries__
98+
weakref.ProxyType.__reversed__ # Doesn't really exist
99+
inspect._ParameterKind.description # Still exists, but stubtest can't see it
100+
asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
101+
asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
102+
103+
# C signature is broader than what is actually accepted
104+
ast.Bytes.__new__
105+
ast.Ellipsis.__new__
106+
ast.ExtSlice.__new__
107+
ast.Index.__new__
108+
ast.NameConstant.__new__
109+
ast.Num.__new__
110+
ast.Str.__new__
111+
asyncio.futures.Future.__init__
112+
asyncio.Future.__init__
113+
contextvars.Context.__init__
114+
queue.SimpleQueue.__init__
115+
xml.etree.ElementTree.XMLParser.__init__
116+
xml.etree.cElementTree.XMLParser.__init__
117+
118+
os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem
119+
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
120+
_ast.ImportFrom.level # None on the class, but never None on instances
121+
ast.ImportFrom.level # None on the class, but never None on instances
122+
123+
# Treated an alias of a typing class in the stubs,
124+
# they are generic to type checkers anyway.
125+
contextlib.AbstractAsyncContextManager.__class_getitem__
126+
contextlib.AbstractContextManager.__class_getitem__
127+
128+
# Super-special typing primitives
129+
typing\._SpecialForm.*
130+
typing._TypedDict.__delitem__
131+
typing._TypedDict.__ior__
132+
typing._TypedDict.__or__
133+
typing._TypedDict.copy
134+
typing._TypedDict.items
135+
typing._TypedDict.keys
136+
typing._TypedDict.pop
137+
typing._TypedDict.setdefault
138+
typing._TypedDict.update
139+
typing._TypedDict.values
140+
typing_extensions\.Final
141+
typing\.NamedTuple
142+
typing\.LiteralString
143+
typing\.Annotated
144+
145+
# White lies around defaults
146+
dataclasses.KW_ONLY
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
_winapi.CreateFileMapping
3+
_winapi.MapViewOfFile
4+
_winapi.OpenFileMapping
5+
_winapi.VirtualQuerySize
6+
asyncio.IocpProactor.recvfrom
7+
asyncio.IocpProactor.recvfrom_into
8+
asyncio.IocpProactor.sendto
9+
asyncio.windows_events.IocpProactor.recvfrom
10+
asyncio.windows_events.IocpProactor.recvfrom_into
11+
asyncio.windows_events.IocpProactor.sendto
12+
msvcrt.GetErrorMode
13+
os.EX_OK
14+
subprocess.STARTUPINFO.copy

tests/stubtest_stdlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def run_stubtest(typeshed_dir: Path) -> int:
5757
str(allowlist_dir / "py3_common.txt"),
5858
"--allowlist",
5959
str(allowlist_dir / version_allowlist),
60+
"--generate-allowlist",
6061
]
6162
if (allowlist_dir / platform_allowlist).exists():
6263
cmd += ["--allowlist", str(allowlist_dir / platform_allowlist)]

0 commit comments

Comments
 (0)