!6734 fix bug of getting python function name

Merge pull request !6734 from fary86/fix_bug_of_get_py_function_name
This commit is contained in:
mindspore-ci-bot 2020-09-23 09:13:25 +08:00 committed by Gitee
commit ea9d39e84b
1 changed files with 3 additions and 1 deletions

View File

@ -339,7 +339,9 @@ def get_object_description(obj, fname, fline):
_, cls_fline = inspect.getsourcelines(obj_cls)
class_loc = f'{cls_fname}:{cls_fline}'
return f"bound method '{obj.__name__}' at {fname}:{fline} of <{class_name} at {class_loc} object>"
if isinstance(obj, (types.FunctionType, ast.FunctionDef)):
if isinstance(obj, types.FunctionType):
return f"function '{obj.__name__}' at {fname}:{fline}"
if isinstance(obj, ast.FunctionDef):
return f"function '{obj.name}' at {fname}:{fline}"
return str(obj)