diff --git a/python/paddle/jit/dy2static/convert_operators.py b/python/paddle/jit/dy2static/convert_operators.py index fceb358cf7652..82fb66cdd29ac 100644 --- a/python/paddle/jit/dy2static/convert_operators.py +++ b/python/paddle/jit/dy2static/convert_operators.py @@ -726,7 +726,7 @@ def convert_var_dtype(var, dtype): } return paddle.cast(var, dtype=cast_map[dtype]) else: - return eval(f'{dtype}(var)') + return eval(dtype)(var) def convert_assert(cond, message=""): diff --git a/python/paddle/jit/dy2static/error.py b/python/paddle/jit/dy2static/error.py index 310bf167abc58..411b3945b6334 100644 --- a/python/paddle/jit/dy2static/error.py +++ b/python/paddle/jit/dy2static/error.py @@ -23,7 +23,7 @@ from .origin_info import Location, OriginInfo, global_origin_info_map from .utils import ( RE_PYMODULE, - _is_api_in_module_helper, # noqa: F401 + _is_api_in_module_helper, ) __all__ = [] @@ -214,9 +214,8 @@ def numpy_api_check(self, format_exception, error_line): func_str = searched_name.group(0) break try: - module_result = eval( - "_is_api_in_module_helper({}, '{}')".format(func_str, "numpy") - ) + fn = eval(func_str) + module_result = _is_api_in_module_helper(fn, "numpy") is_numpy_api_err = module_result or ( func_str.startswith("numpy.") or func_str.startswith("np.") ) diff --git a/python/paddle/jit/dy2static/transformers/call_transformer.py b/python/paddle/jit/dy2static/transformers/call_transformer.py index 8ba0bde462029..74db058aad5e6 100644 --- a/python/paddle/jit/dy2static/transformers/call_transformer.py +++ b/python/paddle/jit/dy2static/transformers/call_transformer.py @@ -15,7 +15,7 @@ from paddle.jit.dy2static.utils import ast_to_source_code, is_paddle_api from paddle.utils import gast -from ..utils import is_builtin # noqa: F401 +from ..utils import is_builtin from .base import BaseTransformer PDB_SET = "pdb.set_trace" @@ -51,9 +51,10 @@ def _no_need_convert_call(self, node): 'enumerate', 'print', } - is_builtin = eval(f"is_builtin({func_str})") # noqa: F811 + fn = eval(func_str) + is_builtin_fn = is_builtin(fn) need_convert = func_str in need_convert_builtin_func_list - return is_builtin and not need_convert + return is_builtin_fn and not need_convert except Exception: return False diff --git a/python/paddle/jit/dy2static/utils_helper.py b/python/paddle/jit/dy2static/utils_helper.py index cec81940a72a3..b23df0b7d422c 100644 --- a/python/paddle/jit/dy2static/utils_helper.py +++ b/python/paddle/jit/dy2static/utils_helper.py @@ -66,7 +66,8 @@ def is_api_in_module(node, module_prefix): import paddle.jit.dy2static as _jst # noqa: F401 from paddle import to_tensor # noqa: F401 - return eval(f"_is_api_in_module_helper({func_str}, '{module_prefix}')") + fn = eval(func_str) + return _is_api_in_module_helper(fn, module_prefix) except Exception: return False