diff --git a/.github/workflows/persubmit.yml b/.github/workflows/persubmit.yml index f598a7a2cf7b6..78606899cc57f 100644 --- a/.github/workflows/persubmit.yml +++ b/.github/workflows/persubmit.yml @@ -16,8 +16,8 @@ jobs: - os: macos-latest python: 3.7 with_cc: OFF - - os: ubuntu-16.04 # TODO(archibate): windows-latest - python: 3.8 + - os: ubuntu-latest + python: 3.9 with_cc: OFF - os: ubuntu-latest python: 3.8 diff --git a/python/taichi/lang/transformer.py b/python/taichi/lang/transformer.py index e7cc3ccc245b4..8d27e5cc52963 100644 --- a/python/taichi/lang/transformer.py +++ b/python/taichi/lang/transformer.py @@ -220,7 +220,8 @@ def visit_Assign(self, node): def tuple_indexed(i): indexing = self.parse_stmt('__tmp_tuple[0]') - indexing.value.slice.value = self.parse_expr("{}".format(i)) + self.set_subscript_index(indexing.value, + self.parse_expr("{}".format(i))) return indexing.value for i, target in enumerate(targets): @@ -565,15 +566,32 @@ def visit_For(self, node): else: # Struct for return self.visit_struct_for(node, is_grouped=False) + @staticmethod + def get_subscript_index(node): + assert isinstance(node, ast.Subscript), type(node) + # ast.Index has been deprecated in Python 3.9, + # use the index value directly instead :) + if isinstance(node.slice, ast.Index): + return node.slice.value + return node.slice + + @staticmethod + def set_subscript_index(node, value): + assert isinstance(node, ast.Subscript), type(node) + if isinstance(node.slice, ast.Index): + node.slice.value = value + else: + node.slice = value + def visit_Subscript(self, node): self.generic_visit(node) value = node.value - indices = node.slice - if isinstance(indices.value, ast.Tuple): - indices = indices.value.elts + indices = self.get_subscript_index(node) + if isinstance(indices, ast.Tuple): + indices = indices.elts else: - indices = [indices.value] + indices = [indices] call = ast.Call(func=self.parse_expr('ti.subscript'), args=[value] + indices, diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000..59b7fd8c6524c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +setuptools +astor +pybind11 +pylint +sourceinspect +pytest +pytest-rerunfailures +pytest-xdist +yapf +numpy +GitPython +coverage +colorama +autograd