def origin(self):
"""
Gets a 2-tuple (file, line) describing the source file where this constituent
is defined or None if the location cannot be determined.
"""
suitepy = self.suite.suite_py()
if exists(suitepy):
import tokenize
with open(suitepy) as fp:
candidate = None
for t in tokenize.generate_tokens(fp.readline):
_, tval, (srow, _), _, _ = t
if candidate is None:
if tval == '"' + self.name + '"' or tval == "'" + self.name + "'":
candidate = srow
else:
if tval == ':':
return (suitepy, srow)
else:
candidate = None
评论列表
文章目录