util.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:metapensiero.pj 作者: azazel75 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号