Skip to content

Commit d1f3a0b

Browse files
committed
Bugfox: ast in python 3.8
1 parent 96931d8 commit d1f3a0b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

python/asthelper.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ def _handle_functions(self, node):
9090
for arg in chain(node.args.args, node.args.kwonlyargs):
9191
type_hint = None
9292
if arg.annotation is not None:
93-
type_hint = ast.unparse(arg.annotation)
93+
# ast.unparse doesn't work in python 3.8, needs to use astunparse instead
94+
if sys.version_info[0] == 3 and sys.version_info[1] == 8:
95+
import astunparse
96+
type_hint = astunparse.unparse(arg.annotation)
97+
else:
98+
type_hint = ast.unparse(arg.annotation)
9499
self.arguments.append({"arg": arg.arg, "type": type_hint})
95100
if len(self.arguments) > 0 and (
96101
self.arguments[0]["arg"] == "self" or self.arguments[0]["arg"] == "cls"

0 commit comments

Comments
 (0)