未验证 提交 95b081ef 编写于 作者: 0 0x45f 提交者: GitHub

Replace comments with blank lines so that error messages are not misplaced (#39035)

上级 9cfa811e
...@@ -548,8 +548,10 @@ def func_to_source_code(function, dedent=True): ...@@ -548,8 +548,10 @@ def func_to_source_code(function, dedent=True):
"The type of 'function' should be a function or method, but received {}.". "The type of 'function' should be a function or method, but received {}.".
format(type(function).__name__)) format(type(function).__name__))
source_code_list, _ = inspect.getsourcelines(function) source_code_list, _ = inspect.getsourcelines(function)
# Replace comments with blank lines so that error messages are not misplaced
source_code_list = [ 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) source_code = ''.join(source_code_list)
if dedent: if dedent:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册