Skip to content

Commit c7e29ec

Browse files
ast: Precise type for ast.Constant.value (python#14159)
1 parent e53e233 commit c7e29ec

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

stdlib/ast.pyi

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,20 +1095,28 @@ if sys.version_info >= (3, 14):
10951095
**kwargs: Unpack[_Attributes],
10961096
) -> Self: ...
10971097

1098+
if sys.version_info >= (3, 10):
1099+
from types import EllipsisType
1100+
1101+
_ConstantValue: typing_extensions.TypeAlias = str | bytes | bool | int | float | complex | None | EllipsisType
1102+
else:
1103+
# Rely on builtins.ellipsis
1104+
_ConstantValue: typing_extensions.TypeAlias = str | bytes | bool | int | float | complex | None | ellipsis # noqa: F821
1105+
10981106
class Constant(expr):
10991107
if sys.version_info >= (3, 10):
11001108
__match_args__ = ("value", "kind")
1101-
value: Any # None, str, bytes, bool, int, float, complex, Ellipsis
1109+
value: _ConstantValue
11021110
kind: str | None
11031111
if sys.version_info < (3, 14):
11041112
# Aliases for value, for backwards compatibility
1105-
s: Any
1106-
n: int | float | complex
1113+
s: _ConstantValue
1114+
n: _ConstantValue
11071115

1108-
def __init__(self, value: Any, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
1116+
def __init__(self, value: _ConstantValue, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...
11091117

11101118
if sys.version_info >= (3, 14):
1111-
def __replace__(self, *, value: Any = ..., kind: str | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
1119+
def __replace__(self, *, value: _ConstantValue = ..., kind: str | None = ..., **kwargs: Unpack[_Attributes]) -> Self: ...
11121120

11131121
class Attribute(expr):
11141122
if sys.version_info >= (3, 10):

0 commit comments

Comments
 (0)