Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] Add experimental Python 3.9 support #2157

Merged
merged 2 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/persubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions python/taichi/lang/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
setuptools
astor
pybind11
pylint
sourceinspect
pytest
pytest-rerunfailures
pytest-xdist
yapf
numpy
GitPython
coverage
colorama
autograd