From 02284e4151c2b1d549a64175ef0e3212b7737c56 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sun, 14 Mar 2021 10:54:48 -0400 Subject: [PATCH] Handle AST.expr in _Subscript() The ast module in Python 3.9 has some API changes. Quoting [1]: Simplified AST for subscription. Simple indices will be represented by their value, extended slices will be represented as tuples. Index(value) will return a value itself, ExtSlice(slices) will return Tuple(slices, Load()). (Contributed by Serhiy Storchaka in bpo-34822.) [1] https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-python-api isinstance(thing, ast.Index) always return false in Python >= 3.9, so we need to handle... whatever the value is now. ast.expr catches 20 of the remaining 24 failures. The remaining 4 are resolved in the next patch. Fixes: #299 --- rope/base/evaluate.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rope/base/evaluate.py b/rope/base/evaluate.py index 610d34e0e..4634981a5 100644 --- a/rope/base/evaluate.py +++ b/rope/base/evaluate.py @@ -307,6 +307,9 @@ def _Subscript(self, node): elif isinstance(node.slice, ast.Slice): self._call_function(node.value, '__getitem__', [node.slice]) + elif isinstance(node.slice, ast.expr): + self._call_function(node.value, '__getitem__', + [node.value]) def _Slice(self, node): self.result = self._get_builtin_name('slice')