Skip to content

Fix #836: correct _const_node_type_names fallback for Python 3.14+#837

Open
EhteshamSid wants to merge 1 commit intopython-rope:masterfrom
EhteshamSid:fix/py314-const-node-type-names
Open

Fix #836: correct _const_node_type_names fallback for Python 3.14+#837
EhteshamSid wants to merge 1 commit intopython-rope:masterfrom
EhteshamSid:fix/py314-const-node-type-names

Conversation

@EhteshamSid
Copy link
Copy Markdown

Fixes #836.

ast._const_node_type_names was removed in Python 3.14. The except ImportError fallback in rope/base/ast.py already handled this case at the assertion level, but the fallback dict still used the old pre-3.8 names ("Num", "Str", "NameConstant", etc.). On Python 3.14 all constant literals are ast.Constant nodes, so the fallback dict should map every type to "Constant" instead.

Split the except block into two branches: >= (3, 8) (i.e. Python 3.14+ which removed the attribute) uses "Constant" for all types; < (3, 8) keeps the original mapping for the old node types. Also removed the bare assert since the if/else now makes the intent explicit.

Added ConstNodeTypeNamesTest to cover the expected return values of get_const_subtype_name() per Python version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImportError: cannot import name '_const_node_type_names' from 'ast' (/usr/lib/python3.14/ast.py)

1 participant