Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
fluiddyn
transonic
Commits
f920d1916e2e
Commit
9c5c8e7f
authored
Sep 13, 2019
by
Pierre Augier
Browse files
Compatibility gast
parent
1f7836f28aca
Changes
5
Hide whitespace changes
Inline
Side-by-side
setup.cfg
View file @
f920d191
...
...
@@ -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
...
...
transonic/analyses/blocks_if.py
View file @
f920d191
...
...
@@ -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
)
...
...
transonic/analyses/extast.py
View file @
f920d191
...
...
@@ -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
...
...
transonic/analyses/util.py
View file @
f920d191
...
...
@@ -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
(
ext
ast
.
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
(
ext
ast
.
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
=
[
ext
ast
.
Name
(
"annotations"
,
ast
.
Store
())],
value
=
ast
.
Dict
(
keys
=
[],
values
=
[]),
)
...
...
transonic/backends/cython.py
View file @
f920d191
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment