From 430167274497eaff5c2bf16e605b0b074364dabb Mon Sep 17 00:00:00 2001 From: Muhamed Fazal PS Date: Wed, 8 Jul 2026 17:22:52 +0530 Subject: [PATCH] fix: support Python 3.14 removal of _const_node_type_names from ast Python 3.14 removed the internal _const_node_type_names mapping from the ast module and uses ast.Constant for all constant node types. The existing fallback only supported Python < 3.8, causing an ImportError on Python >= 3.14. Split the fallback into two paths: - Python >= 3.14: map all constant types to 'Constant' - Older Python: keep the legacy type names (NameConstant, Num, Str, etc.) Fixes #836. --- rope/base/ast.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/rope/base/ast.py b/rope/base/ast.py index 16c44da4..25c85a2d 100644 --- a/rope/base/ast.py +++ b/rope/base/ast.py @@ -8,18 +8,32 @@ # Suppress the mypy complaint: Module "ast" has no attribute "_const_node_type_names" from ast import _const_node_type_names # type:ignore except ImportError: - # backported from stdlib `ast` - assert sys.version_info < (3, 8) or sys.version_info >= (3, 14) - _const_node_type_names = { - bool: "NameConstant", # should be before int - type(None): "NameConstant", - int: "Num", - float: "Num", - complex: "Num", - str: "Str", - bytes: "Bytes", - type(...): "Ellipsis", - } + # Python < 3.8 didn't have `_const_node_type_names`; Python >= 3.14 + # removed it. In both cases, provide a fallback mapping. + if sys.version_info >= (3, 14): + # Python 3.14+ uses ast.Constant for all constants + _const_node_type_names = { + bool: "Constant", + type(None): "Constant", + int: "Constant", + float: "Constant", + complex: "Constant", + str: "Constant", + bytes: "Constant", + type(...): "Constant", + } + else: + assert sys.version_info < (3, 8) + _const_node_type_names = { + bool: "NameConstant", # should be before int + type(None): "NameConstant", + int: "Num", + float: "Num", + complex: "Num", + str: "Str", + bytes: "Bytes", + type(...): "Ellipsis", + } def parse(source, filename="", *args, **kwargs): # type: ignore