functemplate: Adapt ast syntax to PEP570 changes on python3.8
@@ -118,26 +118,32 @@ def compile_func(arg_names, statements, name='_the_func', debug=False):
bytecode of the compiled function.
"""
if six.PY2:
- func_def = ast.FunctionDef(
- name=name.encode('utf-8'),
+ name = name.encode('utf-8')
args = ast.arguments(
args=[ast.Name(n, ast.Param()) for n in arg_names],
vararg=None,
kwarg=None,
defaults=[ex_literal(None) for _ in arg_names],
- ),
- body=statements,
- decorator_list=[],
+ )
+ elif sys.version_info >= (3, 8):
+ args = ast.arguments(
+ args=[ast.arg(arg=n, annotation=None) for n in arg_names],
+ posonlyargs=[],
+ kwonlyargs=[],
+ kw_defaults=[],
+ defaults=[ex_literal(None) for _ in arg_names],
)
else:
- func_def = ast.FunctionDef(
- name=name,
args = ast.arguments(
args=[ast.arg(arg=n, annotation=None) for n in arg_names],
kwonlyargs=[],
kw_defaults=[],
defaults=[ex_literal(None) for _ in arg_names],
- ),
+ )
+
+ func_def = ast.FunctionDef(
+ name=name,
+ args=args,
body=statements,
decorator_list=[],
)
