Commit 802104a5 authored by Pierre Augier's avatar Pierre Augier
Browse files

Simplify replace_strings_by_objects to avoid a possible bug

parent 7071c98191cc
Pipeline #6867 passed with stage
in 9 minutes and 14 seconds
......@@ -332,9 +332,7 @@ def analyse_aot(code, pathfile, backend_name):
blocks = get_block_definitions(code, module, ancestors, duc, udc)
for block in blocks:
replace_strings_by_objects(
block.signatures, module, ancestors, udc, duc, namespace
)
replace_strings_by_objects(block.signatures, module, ancestors, udc, duc)
debug(pformat(blocks))
......@@ -414,9 +412,7 @@ def analyse_aot(code, pathfile, backend_name):
] = extract_returns_annotation(fdef.returns, namespace)
for signatures in annotations["__in_comments__"].values():
replace_strings_by_objects(
signatures, module, ancestors, udc, duc, namespace
)
replace_strings_by_objects(signatures, module, ancestors, udc, duc)
debug("annotations:\n" + pformat(annotations))
......
......@@ -53,23 +53,18 @@ def create_objects_from_names(names, module, ancestors, udc, duc):
return namespace
def replace_strings_by_objects(
signatures: dict, module, ancestors, udc, duc, namespace_from_code
):
def replace_strings_by_objects(signatures: dict, module, ancestors, udc, duc):
"""Replace strings in signatures by objects defined in the code"""
types_NameError = set()
for signature in signatures:
for var_str, type_as_str in signature.items():
if type_as_str in namespace_from_code:
signature[var_str] = namespace_from_code[type_as_str]
else:
try:
signature[var_str] = eval(type_as_str)
except NameError:
types_NameError.add(type_as_str)
except (SyntaxError, TypeError):
pass
try:
signature[var_str] = eval(type_as_str)
except NameError:
types_NameError.add(type_as_str)
except (SyntaxError, TypeError):
pass
namespace = create_objects_from_names(
types_NameError, module, ancestors, udc, duc
......
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