From a2a6aee89213d87ed6f86cf723a7fc4ed3c219a2 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 5 Feb 2024 01:42:20 +0000 Subject: [PATCH] Fix annotation for ast.alias.name (#11364) This isn't necessarily always an identifier: ```pycon >>> print(ast.dump(ast.parse('from typing import *'), indent=2)) Module( body=[ ImportFrom( module='typing', names=[ alias(name='*')], level=0)], type_ignores=[]) >>> '*'.isidentifier() False ``` --- stdlib/_ast.pyi | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stdlib/_ast.pyi b/stdlib/_ast.pyi index fc3f035cc..0758450df 100644 --- a/stdlib/_ast.pyi +++ b/stdlib/_ast.pyi @@ -6,6 +6,10 @@ PyCF_ONLY_AST: Literal[1024] PyCF_TYPE_COMMENTS: Literal[4096] PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192] +# Alias used for fields that must always be valid identifiers +# A string `x` counts as a valid identifier if both the following are True +# (1) `x.isidentifier()` evaluates to `True` +# (2) `keyword.iskeyword(x)` evaluates to `False` _Identifier: typing_extensions.TypeAlias = str class AST: @@ -499,7 +503,7 @@ class keyword(AST): class alias(AST): if sys.version_info >= (3, 10): __match_args__ = ("name", "asname") - name: _Identifier + name: str asname: _Identifier | None class withitem(AST):