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

More f-strings

parent e046c45372e9
......@@ -209,18 +209,16 @@ def find_path(node: object, pathfile: str):
def change_import_name(
code_dep: str, changed_node: object, func_name: str, relative: str = None
):
""" Change the name of changed_node in code_dep by adding "__" + func + "__"
at the beginning of the imported module, and return the modified code
"""Change the name of changed_node in code_dep by adding "__" + func + "__"
at the beginning of the imported module, and return the modified code
"""
mod = extast.parse(code_dep)
for node in mod.body:
if extast.unparse(node) == extast.unparse(changed_node):
if isinstance(node, ast.ImportFrom):
node.module = "__ext__" + func_name + "__" + node.module
node.module = f"__ext__{func_name}__{node.module}"
elif isinstance(node, ast.Import):
node.names[0].name = (
"__ext__" + func_name + "__" + node.names[0].name
)
node.names[0].name = f"__ext__{func_name}__{node.names[0].name}"
if not relative:
node.level = 0
return extast.unparse(mod)
......@@ -380,7 +378,7 @@ def get_exterior_code(
# a jitted function or method needs another jitted function
if not (file_name and file_name not in treated):
continue
new_file_name = "__ext__" + func + "__" + file_name
new_file_name = f"__ext__{func}__{file_name}"
# get the content of the file
try:
with open(str(file_path), "r") as file:
......
......@@ -27,11 +27,7 @@ def _make_code_from_fdef_node(fdef, black=True):
transformed = TypeHintRemover().visit(fdef)
# convert the AST back to source code
code = extast.unparse(transformed)
if black:
code = format_str(code)
return code
return format_str(code)
class Backend:
......@@ -95,7 +91,7 @@ class Backend:
if not path_py.exists():
raise FileNotFoundError(f"Input file {path_py} not found")
if path_py.absolute().parent.name == "__" + self.name + "__":
if path_py.absolute().parent.name == f"__{self.name}__":
logger.debug(f"skip file {path_py}")
return None, None, None
if not path_py.name.endswith(".py"):
......@@ -103,7 +99,7 @@ class Backend:
"transonic only processes Python file. Cannot process {path_py}"
)
path_dir = path_py.parent / str("__" + self.name + "__")
path_dir = path_py.parent / str(f"__{self.name}__")
path_backend = (path_dir / path_py.name).with_suffix(self.suffix_backend)
if not has_to_build(path_backend, path_py) and not force:
......
......@@ -184,7 +184,7 @@ class CythonBackend(BackendAOT):
name_type_args = []
for arg in [name.id for name in fdef.args.args]:
ctypedef = []
name_type_arg = "__" + fdef.name + "_" + arg
name_type_arg = f"__{fdef.name}_{arg}"
name_type_args.append(name_type_arg)
ctypedef.append(f"ctypedef fused {name_type_arg}:\n")
possible_types = [x[index] for x in signatures_as_lists_strings]
......
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