Skip to content

Commit 60a21f2

Browse files
committed
Added unparse file so no installation is required
1 parent d1f3a0b commit 60a21f2

File tree

2 files changed

+728
-3
lines changed

2 files changed

+728
-3
lines changed

python/asthelper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ 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-
# ast.unparse doesn't work in python 3.8, needs to use astunparse instead
93+
# ast.unparse doesn't work for python <= 3.8
9494
if sys.version_info[0] == 3 and sys.version_info[1] == 8:
95-
import astunparse
96-
type_hint = astunparse.unparse(arg.annotation)
95+
from unparse import Unparser
96+
from io import StringIO
97+
v = StringIO()
98+
Unparser(arg.annotation, file=v)
99+
type_hint = v.getvalue()
97100
else:
98101
type_hint = ast.unparse(arg.annotation)
99102
self.arguments.append({"arg": arg.arg, "type": type_hint})

0 commit comments

Comments
 (0)