def _pos_in_src(self):
"""Return the position in source of the generated node."""
py_node = self.node.py_node
if py_node:
offset = getattr(py_node, 'col_offset', 0)
# multi-line comments have an offset of -1
if offset < 0:
offset = 0
# special handling of nodes that are decorable. Those nodes expose
# a 'lineno' that starts with the first decorator. for now, take
# the last decorator lineno and add one
if isinstance(py_node, (ast.FunctionDef, ast.AsyncFunctionDef,
ast.ClassDef)) and py_node.decorator_list:
result = (py_node.decorator_list[-1].lineno + 1, offset)
else:
result = (getattr(py_node, 'lineno', None),
offset)
else:
result = (None, None)
return result
评论列表
文章目录