Skip to content

Commit 250f3d9

Browse files
ast: fix stubtest issues (#7877)
Add annotations for `_ast.Tuple.dims` and `ast.main()`. Add allowlist comments for others.
1 parent d389b5f commit 250f3d9

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

stdlib/_ast.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ class Tuple(expr):
415415
__match_args__ = ("elts", "ctx")
416416
elts: list[expr]
417417
ctx: expr_context
418+
if sys.version_info >= (3, 9):
419+
dims: list[expr]
418420

419421
class expr_context(AST): ...
420422

stdlib/ast.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,6 @@ if sys.version_info >= (3, 8):
259259
def get_source_segment(source: str, node: AST, *, padded: bool = ...) -> str | None: ...
260260

261261
def walk(node: AST) -> Iterator[AST]: ...
262+
263+
if sys.version_info >= (3, 9):
264+
def main() -> None: ...

tests/stubtest_allowlists/py310.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
_ast.ImportFrom.level
21
_collections_abc.AsyncGenerator.ag_await
32
_collections_abc.AsyncGenerator.ag_code
43
_collections_abc.AsyncGenerator.ag_frame
@@ -8,7 +7,6 @@ _collections_abc.ItemsView.__reversed__
87
_collections_abc.KeysView.__reversed__
98
_collections_abc.ValuesView.__reversed__
109
_weakref.ProxyType.__reversed__ # Doesn't really exist
11-
ast.ImportFrom.level
1210
asyncio.Future.__init__ # Usually initialized from c object
1311
asyncio.futures.Future.__init__ # Usually initialized from c object
1412
builtins.dict.get
@@ -75,7 +73,6 @@ tempfile.SpooledTemporaryFile.seekable
7573
tempfile.SpooledTemporaryFile.writable
7674

7775
# Exists at runtime, but missing from stubs
78-
_ast.Tuple.dims
7976
_codecs.unregister
8077
_collections_abc.AsyncIterable.__class_getitem__
8178
_collections_abc.Awaitable.__class_getitem__
@@ -85,8 +82,6 @@ _collections_abc.MappingView.__class_getitem__
8582
_csv.Reader
8683
_csv.Writer
8784
_imp.source_hash
88-
ast.Tuple.dims
89-
ast.main
9085
asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this
9186
bdb.Breakpoint.clearBreakpoints
9287
distutils.dist.DistributionMetadata.set_classifiers
@@ -194,6 +189,8 @@ os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all Pat
194189
ssl.PROTOCOL_SSLv3 # Depends on ssl compilation
195190
ssl.RAND_egd # Depends on openssl compilation
196191
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
192+
_ast.ImportFrom.level # None on the class, but never None on instances
193+
ast.ImportFrom.level # None on the class, but never None on instances
197194

198195
# These enums derive from (str, Enum). See comment in py3_common.txt
199196
pstats.SortKey.__new__

tests/stubtest_allowlists/py311.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
_ast.ImportFrom.level
2-
_ast.Tuple.dims
31
_codecs.unregister
42
_collections_abc.AsyncGenerator.ag_await
53
_collections_abc.AsyncGenerator.ag_code
@@ -23,9 +21,6 @@ _operator.itemgetter.__vectorcalloffset__
2321
argparse._AppendConstAction.__init__
2422
argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group
2523
argparse._StoreConstAction.__init__
26-
ast.ImportFrom.level
27-
ast.Tuple.dims
28-
ast.main
2924
asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this
3025
asyncio.sslproto.AppProtocolState
3126
asyncio.sslproto.SSLAgainErrors
@@ -261,6 +256,8 @@ os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all Pat
261256
ssl.PROTOCOL_SSLv3 # Depends on ssl compilation
262257
ssl.RAND_egd # Depends on openssl compilation
263258
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
259+
_ast.ImportFrom.level # None on the class, but never None on instances
260+
ast.ImportFrom.level # None on the class, but never None on instances
264261

265262
# These enums derive from (str, Enum). See comment in py3_common.txt
266263
pstats.SortKey.__new__

tests/stubtest_allowlists/py39.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
_ast.ImportFrom.level
21
_collections_abc.AsyncGenerator.ag_await
32
_collections_abc.AsyncGenerator.ag_code
43
_collections_abc.AsyncGenerator.ag_frame
@@ -10,7 +9,6 @@ _weakref.ProxyType.__reversed__ # Doesn't really exist
109
ast.Bytes.__new__
1110
ast.Ellipsis.__new__
1211
ast.ExtSlice.__new__
13-
ast.ImportFrom.level
1412
ast.Index.__new__
1513
ast.NameConstant.__new__
1614
ast.Num.__new__
@@ -106,15 +104,12 @@ collections.Mapping.get # Adding None to the Union messed up mypy
106104
collections.Sequence.index # Supporting None in end is not mandatory
107105

108106
# Exists at runtime, but missing from stubs
109-
_ast.Tuple.dims
110107
_collections_abc.AsyncIterable.__class_getitem__
111108
_collections_abc.Awaitable.__class_getitem__
112109
_collections_abc.Container.__class_getitem__
113110
_collections_abc.Iterable.__class_getitem__
114111
_collections_abc.MappingView.__class_getitem__
115112
_imp.source_hash
116-
ast.Tuple.dims
117-
ast.main
118113
collections.AsyncIterable.__class_getitem__
119114
collections.Awaitable.__class_getitem__
120115
collections.Container.__class_getitem__
@@ -196,6 +191,8 @@ xml.etree.cElementTree.XMLParser.__init__
196191

197192
ast.FormattedValue.conversion # None on the class, but never None on instances
198193
_ast.FormattedValue.conversion # None on the class, but never None on instances
194+
_ast.ImportFrom.level # None on the class, but never None on instances
195+
ast.ImportFrom.level # None on the class, but never None on instances
199196

200197
ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154
201198
os.PathLike.__class_getitem__ # PathLike is a protocol; we don't expect all PathLike classes to implement class_getitem

0 commit comments

Comments
 (0)