Skip to content

Commit

Permalink
Accessing numerical constant value with node.func.value for Python >=…
Browse files Browse the repository at this point in the history
… 3.8.
  • Loading branch information
alexnick83 committed Oct 8, 2023
1 parent 52011cb commit e4288ed
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions dace/frontend/python/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
from dace.frontend.python.common import (DaceSyntaxError, SDFGConvertible, SDFGClosure, StringLiteral)


if sys.version_info < (3, 8):
BytesConstant = ast.Bytes
EllipsisConstant = ast.Ellipsis
NameConstant = ast.NameConstant
NumConstant = ast.Num
StrConstant = ast.Str
else:
BytesConstant = ast.Constant
EllipsisConstant = ast.Constant
NameConstant = ast.Constant
NumConstant = ast.Constant
StrConstant = ast.Constant


class DaceRecursionError(Exception):
"""
Exception that indicates a recursion in a data-centric parsed context.
Expand Down Expand Up @@ -1358,18 +1372,15 @@ def _get_given_args(self, node: ast.Call, function: 'DaceProgram') -> Set[str]:

def visit_Call(self, node: ast.Call):
# Only parse calls to parsed SDFGConvertibles
if not isinstance(node.func, (ast.Num, ast.Constant)):
if not isinstance(node.func, (NumConstant, ast.Constant)):
self.seen_calls.add(astutils.unparse(node.func))
return self.generic_visit(node)
if hasattr(node.func, 'oldnode'):
if isinstance(node.func.oldnode, ast.Call):
self.seen_calls.add(astutils.unparse(node.func.oldnode.func))
else:
self.seen_calls.add(astutils.rname(node.func.oldnode))
if isinstance(node.func, ast.Num):
value = node.func.n
else:
value = node.func.value
value = node.func.value if sys.version_info >= (3, 8) else node.func.n

if not hasattr(value, '__sdfg__') or isinstance(value, SDFG):
return self.generic_visit(node)
Expand Down

0 comments on commit e4288ed

Please sign in to comment.