From 95b081ef1024687e735977413713936f33cf9920 Mon Sep 17 00:00:00 2001 From: 0x45f <23097963+0x45f@users.noreply.github.com> Date: Mon, 24 Jan 2022 11:26:26 +0800 Subject: [PATCH] Replace comments with blank lines so that error messages are not misplaced (#39035) --- python/paddle/fluid/dygraph/dygraph_to_static/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/utils.py b/python/paddle/fluid/dygraph/dygraph_to_static/utils.py index 51e85901e7d..04474dcdfe5 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: -- GitLab