Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

Commit 9c5c8e7f authored by Pierre Augier's avatar Pierre Augier
Browse files

Compatibility gast

parent 1f7836f28aca
......@@ -13,8 +13,8 @@ classifiers =
python_requires = >= 3.6
install_requires =
astunparse
gast >= 0.3.0
beniget >= 0.2.0
gast
beniget
# black # avoid this dependency for now (see https://github.com/ambv/black/issues/552)
setup_requires = setuptools
......
......@@ -83,7 +83,11 @@ def get_block_definitions(code, module, ancestors, duc, udc):
# no it's not a block definition
continue
name_block = call.args[0].value
try:
# gast >= 0.3.0 (py3.8)
name_block = call.args[0].value
except AttributeError:
name_block = call.args[0].s
rawcode, comments = gather_rawcode_comments(if_node, code)
......
......@@ -167,6 +167,60 @@ class CommentInserter(ast.NodeVisitor):
value.insert(index, CommentLine(comment, lineno))
try:
ast.Constant
except AttributeError:
# gast < 0.3.0
class Constant(ast.Str):
def __init__(self, value):
super().__init__(value)
class Name(ast.Name):
def __init__(self, id="annotations", ctx=ast.Store(), annotation=None):
super().__init__(id, ctx, annotation)
class FunctionDef(ast.FunctionDef):
def __init__(
self,
name,
args,
body,
decorator_list=None,
returns=None,
type_comment=None,
):
if decorator_list is None:
decorator_list = []
super().__init__(name, args, body, decorator_list, returns)
else:
# gast >= 0.3.0
class Constant(ast.Constant):
def __init__(self, value):
super().__init__(value, None)
class Name(ast.Name):
def __init__(self, id="annotations", ctx=ast.Store(), annotation=None):
super().__init__(id, ctx, annotation, None)
class FunctionDef(ast.FunctionDef):
def __init__(
self,
name,
args,
body,
decorator_list=None,
returns=None,
type_comment=None,
):
if decorator_list is None:
decorator_list = []
super().__init__(
name, args, body, decorator_list, returns, type_comment
)
if __name__ == "__main__":
code = """
# comment 0
......
......@@ -44,7 +44,7 @@ def _fill_ast_annotations_function(function_def, ast_annotations):
except AttributeError:
name = arg.id
dict_node.keys.append(ast.Constant(value=name, kind=None))
dict_node.keys.append(extast.Constant(value=name))
dict_node.values.append(arg.annotation)
......@@ -57,7 +57,7 @@ def _fill_ast_annotations_class(class_def, ast_annotations):
if node.annotation is not None:
name = node.target.id
dict_node.keys.append(ast.Constant(value=name, kind=None))
dict_node.keys.append(extast.Constant(value=name))
dict_node.values.append(node.annotation)
......@@ -67,7 +67,7 @@ def get_annotations(object_def, namespace):
# print_dump(object_def)
ast_annotations = ast.Assign(
targets=[ast.Name("annotations", ast.Store(), None, None)],
targets=[extast.Name("annotations", ast.Store())],
value=ast.Dict(keys=[], values=[]),
)
......
......@@ -23,7 +23,7 @@ from pprint import pprint
from warnings import warn
import itertools
from transonic.analyses.extast import unparse, ast
from transonic.analyses.extast import unparse, ast, FunctionDef
from transonic.annotation import (
compute_pythran_type_from_type,
make_signatures_from_typehinted_func,
......@@ -218,14 +218,7 @@ class CythonBackend(BackendAOT):
inline = decorator_keywords.get("inline", False)
inline = "inline " if inline else ""
fdef = ast.FunctionDef(
name=fdef.name,
args=copy.deepcopy(fdef.args),
body=[],
decorator_list=[],
returns=None,
type_comment=None,
)
fdef = FunctionDef(name=fdef.name, args=copy.deepcopy(fdef.args), body=[])
assert isinstance(annotations, list)
......@@ -332,14 +325,7 @@ class CythonBackend(BackendAOT):
inline = decorator_keywords.get("inline", False)
inline = "inline " if inline else ""
fdef = ast.FunctionDef(
name=fdef.name,
args=copy.deepcopy(fdef.args),
body=[],
decorator_list=[],
returns=None,
type_comment=None,
)
fdef = FunctionDef(name=fdef.name, args=copy.deepcopy(fdef.args), body=[])
signatures_func = []
if signatures_as_lists_strings:
# produce ctypedef
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment