Skip to content

Commit

Permalink
Handle AST.expr in _Subscript()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mattst88 committed Mar 19, 2021
1 parent a63ae26 commit 02284e4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rope/base/evaluate.py
Expand Up @@ -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')
Expand Down

0 comments on commit 02284e4

Please sign in to comment.