diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/utils.py b/python/paddle/fluid/dygraph/dygraph_to_static/utils.py index 51e85901e7d558c697382c5d433c2cc7661c3213..04474dcdfe5091b2986eeeedb9870c00d83970db 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/utils.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/utils.py @@ -548,8 +548,10 @@ def func_to_source_code(function, dedent=True): "The type of 'function' should be a function or method, but received {}.". format(type(function).__name__)) source_code_list, _ = inspect.getsourcelines(function) + # Replace comments with blank lines so that error messages are not misplaced source_code_list = [ - line for line in source_code_list if not line.lstrip().startswith('#') + line if not line.lstrip().startswith('#') else '\n' + for line in source_code_list ] source_code = ''.join(source_code_list) if dedent: