Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not decorator_keywords.get("wraparound", True):
parts.append("@cython.wraparound(False)")
if decorator_keywords.get("cdivision", False):
parts.append("@cython.cdivision(True)")
if not decorator_keywords.get("nonecheck", True):
parts.append("@cython.noneckeck(False)")
if decorator_keywords.get("nogil", False):
parts.append("@cython.nogil")
transformed = TypeHintRemover().visit(fdef)
# convert the AST back to source code
parts.append(unparse(transformed))
return format_str("\n".join(parts))
if isinstance(node, ast.FunctionDef):
if node.name == extast.unparse(name).rstrip("\n\r"):
ancestors = beniget.Ancestors()
ancestors.visit(module)
duc = beniget.DefUseChains()
duc.visit(module)
udc = beniget.UseDefChains(duc)
capturex = CaptureX(
[node],
module,
ancestors,
defuse_chains=duc,
usedef_chains=udc,
consider_annotations=None,
)
lines_code.append(str(extast.unparse(node)))
code_dependance_annotations = capturex.make_code_external()
if isinstance(node, ast.Assign):
if node.targets[0].id == extast.unparse(name).rstrip("\n\r"):
lines_code.append(str(extast.unparse(node)))
if isinstance(node, ast.ClassDef):
if node.name == extast.unparse(name).rstrip("\n\r"):
lines_code.append(str(extast.unparse(node)))
return code_dependance_annotations + "\n".join(lines_code)
)
# remove the definition:
for node in module_body:
# of the jitted function in the file
if isinstance(node, ast.FunctionDef):
if node.name in jitted_functions:
module.body.remove(node)
# of the jitted imported function
if isinstance(node, ast.ImportFrom):
for name in node.names:
if name.name in jitted_functions:
node.names.remove(name)
# remove the importFrom if no function is imported
if not node.names:
module.body.remove(node)
return extast.unparse(module), jitted_dicts, special, jitted_functions
def extract_variable_annotations(fdef, namespace):
variable_types = {}
for node in fdef.body:
if isinstance(node, ast.AnnAssign):
name = node.target.id
source = extast.unparse(node.annotation)
result = eval(source, namespace)
variable_types[name] = result
return variable_types
str_variables = ", ".join(block.signatures[0].keys())
fdef_block = extast.ast.parse(
f"""def {block.name}({str_variables}):pass"""
).body[0]
# TODO: locals_types for blocks
locals_types = None
signatures_blocks.extend(
self._make_header_from_fdef_annotations(
fdef_block, block.signatures, locals_types
)
)
code.append(f"\ndef {block.name}({str_variables}):\n")
code.append(indent(extast.unparse(block.ast_code), " "))
if block.results:
code.append(f" return {', '.join(block.results)}\n")
arguments_blocks = {
block.name: list(block.signatures[0].keys()) for block in blocks
}
if arguments_blocks:
self._append_line_header_variable(
signatures_blocks, "arguments_blocks"
)
code.append(f"arguments_blocks = {str(arguments_blocks)}\n")
return signatures_blocks, code
if isinstance(node, ast.Import):
if node.names[0].name in ["transonic", "numpy"]:
kept.append(node)
else:
def_ = duc.chains[node.names[0]]
fill_suppressed(def_)
# suppressed.add()
elif isinstance(node, ast.ImportFrom):
if node.module in ["transonic", "numpy"]:
kept.append(node)
elif isinstance(node, (ast.Assign, ast.AugAssign)):
kept.append(node)
return extast.unparse(module_filtered)