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 5ccd3157 authored by Pierre Augier's avatar Pierre Augier
Browse files

More type annotations removed for Pythran

parent 3806116762d2
......@@ -216,9 +216,7 @@ class Transonic:
suffix = ".py"
self.path_backend = path_backend = (
path_mod.parent
/ f"__{backend.name}__"
/ (module_short_name + suffix)
path_mod.parent / f"__{backend.name}__" / (module_short_name + suffix)
)
path_ext = None
......@@ -281,11 +279,11 @@ class Transonic:
and not self.path_extension.exists()
):
if mpi.rank == 0:
print(f"Launching {backend.name_capitalized} to compile a new extension...")
print(
f"Launching {backend.name_capitalized} to compile a new extension..."
)
self.process = compile_extension(
path_backend,
backend.name,
name_ext_file=self.path_extension.name,
path_backend, backend.name, name_ext_file=self.path_extension.name
)
self.is_compiling = True
self.is_compiled = False
......
from transonic.analyses.extast import parse
from .util import print_dumped, print_unparsed
source = "def func(): return True"
def test_print_dumped():
print_dumped(source)
def test_print_unparsed():
node = parse(source)
print_unparsed(node)
......@@ -3,11 +3,9 @@
"""
import re
import inspect
import beniget
from pathlib import Path
from textwrap import dedent
from typing import Callable
import gast as ast
from transonic.analyses import extast
from transonic.analyses.capturex import CaptureX
......@@ -263,7 +261,7 @@ def adapt_code_dependance(func: str, codes_dependance: str, jitted_dicts: dict):
Adapt code_dependance to the call of a jitted function in a jitted function:
- Remove the import transonic
- Remove the jitted function statement (i.e func = jit(func))
- Add a import statement to the jitted function
- Add a import statement to the jitted function
- remove the definition of the jitted function if its on the file, or remove the import statement
"""
special = []
......
......@@ -179,13 +179,14 @@ class Backend:
# Deal with functions
for func_name, fdef in boosted_dicts["functions"].items():
code_function = self.get_code_function(fdef)
signatures_func = self.get_signatures(func_name, fdef, annotations)
if self.name == "pythran":
code.append("\n".join(sorted(signatures_func)))
elif self.name == "cython":
if signatures_func:
signature_pxd = signature_pxd + signatures_func
code_function = self.get_code_function(fdef)
code.append(code_function)
# Deal with methods
......
......@@ -8,7 +8,10 @@ from transonic import Transonic, boost, Array, Union
@boost
def func(a, b):
return a + b
i: int
i = 2
c: float = 0.1 + i
return a + b + c
def func_tmp(arg):
......
......@@ -50,7 +50,7 @@ import sys
import inspect
import re
from pathlib import Path
import ast
import gast as ast
import importlib.util
from distutils.util import strtobool
import shutil
......@@ -190,21 +190,29 @@ class TypeHintRemover(ast.NodeTransformer):
from https://stackoverflow.com/a/42734810/1779806
"""
def visit_FunctionDef(self, node):
def visit_FunctionDef(self, fdef):
# remove the return type defintion
node.returns = None
fdef.returns = None
# remove all argument annotations
if node.args.args:
for arg in node.args.args:
if fdef.args.args:
for arg in fdef.args.args:
arg.annotation = None
return node
body = []
for node in fdef.body:
if isinstance(node, ast.AnnAssign):
if node.value is None:
continue
node = ast.Assign(targets=[node.target], value=node.value)
body.append(node)
fdef.body = body
return fdef
def strip_typehints(source):
"""Strip the type hints from a function"""
source = format_str(source)
# parse the source code into an AST
parsed_source = ast.parse(source)
# remove all type annotations, function return type definitions
......@@ -212,12 +220,7 @@ def strip_typehints(source):
transformed = TypeHintRemover().visit(parsed_source)
# convert the AST back to source code
striped_code = astunparse.unparse(transformed)
# bad hack to conserve the comments...
sep = ":(\n)+ "
head = re.split(sep, striped_code, maxsplit=1)[0]
body = re.split(sep, source, maxsplit=1)[-1]
return head + ":\n " + body
return striped_code
def get_ipython_input(last=True):
......
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