Skip to content

Commit

Permalink
Merge pull request #333 from mattst88/python-3.9-ast-changes
Browse files Browse the repository at this point in the history
Python 3.9 ast changes
  • Loading branch information
mcepl committed Mar 20, 2021
2 parents 0aec7ea + 46a3403 commit 4dba2ff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions rope/base/evaluate.py
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions rope/base/oi/soa.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _evaluate_assign_value(self, node, nodes, type_hint=False):
for subscript, levels in nodes:
instance = evaluate.eval_node(self.scope, subscript.value)
args_pynames = [evaluate.eval_node(self.scope,
subscript.slice.value)]
subscript.slice)]
value = rope.base.oi.soi._infer_assignment(
rope.base.pynames.AssignmentValue(node.value, levels,
type_hint=type_hint),
Expand All @@ -149,5 +149,5 @@ def __init__(self):

def _added(self, node, levels):
if isinstance(node, rope.base.ast.Subscript) and \
isinstance(node.slice, rope.base.ast.Index):
isinstance(node.slice, (rope.base.ast.Index, rope.base.ast.expr)):
self.nodes.append((node, levels))
18 changes: 13 additions & 5 deletions ropetest/refactor/patchedasttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,12 @@ def test_ext_slice_node(self):
source = 'x = xs[0,:]\n'
ast_frag = patchedast.get_patched_ast(source, True)
checker = _ResultChecker(self, ast_frag)
checker.check_region('ExtSlice', 7, len(source) - 2)
checker.check_children('ExtSlice', ['Index', '', ',', '', 'Slice'])
if sys.version_info >= (3, 9):
checker.check_region('Tuple', 7, len(source) - 2)
checker.check_children('Tuple', ['Num', '', ',', '', 'Slice'])
else:
checker.check_region('ExtSlice', 7, len(source) - 2)
checker.check_children('ExtSlice', ['Index', '', ',', '', 'Slice'])

def test_simple_module_node(self):
source = 'pass\n'
Expand Down Expand Up @@ -933,9 +937,13 @@ def test_simple_subscript(self):
source = 'a[1]\n'
ast_frag = patchedast.get_patched_ast(source, True)
checker = _ResultChecker(self, ast_frag)
checker.check_children(
'Subscript', ['Name', '', '[', '', 'Index', '', ']'])
checker.check_children('Index', ['Num'])
if sys.version_info >= (3, 9):
checker.check_children(
'Subscript', ['Name', '', '[', '', 'Num', '', ']'])
else:
checker.check_children(
'Subscript', ['Name', '', '[', '', 'Index', '', ']'])
checker.check_children('Index', ['Num'])

def test_tuple_node(self):
source = '(1, 2)\n'
Expand Down

0 comments on commit 4dba2ff

Please sign in to comment.