Skip to content

Commit 775b0ef

Browse files
authored
Merge pull request #30 from joeyism/master
Bugfix: module 'ast' has no attribute 'unparse'
2 parents 4f02ef2 + 09bc3ba commit 775b0ef

File tree

2 files changed

+731
-1
lines changed

2 files changed

+731
-1
lines changed

python/asthelper.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ 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 for python <= 3.8
94+
if sys.version_info[0] == 3 and sys.version_info[1] <= 8:
95+
from unparse import Unparser
96+
from io import StringIO
97+
v = StringIO()
98+
Unparser(arg.annotation, file=v)
99+
type_hint = v.getvalue()
100+
else:
101+
type_hint = ast.unparse(arg.annotation)
94102
self.arguments.append({"arg": arg.arg, "type": type_hint})
95103
if len(self.arguments) > 0 and (
96104
self.arguments[0]["arg"] == "self" or self.arguments[0]["arg"] == "cls"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy