提交 dab7ad44 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!2901 Optimization for parser

Merge pull request !2901 from Kang/master
......@@ -334,7 +334,7 @@ class Parser:
def __init__(self, fn: (types.FunctionType, types.MethodType), parse_method=None) -> None:
self.fn = fn
self.parse_method = parse_method
_, self.line_offset = inspect.getsourcelines(self.fn)
self.line_offset = 0
self.filename: str = inspect.getfile(self.fn)
# Used to resolve the function's globals Namespace.
......@@ -350,7 +350,8 @@ class Parser:
logger.debug("fn = %r", self.fn)
tree = None
if isinstance(self.fn, (types.FunctionType, types.MethodType)):
original_src = inspect.getsource(self.fn)
lines, self.line_offset = inspect.getsourcelines(self.fn)
original_src = ''.join(lines)
hexstr = hashlib.sha256(original_src.encode()).hexdigest()
tree = Parser.ast_cache.get(hexstr)
if not tree:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册