如何检索 pylint 消息的列偏移量? [英] how can i retrieve column offsets for pylint messages?

查看:52
本文介绍了如何检索 pylint 消息的列偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自己格式化 pylint 的输出,所以我直接调用 pylint.lint.Run,​​并接收对我的 add_message 方法的回调.过程非常顺利,但我需要消息的列偏移量来构建我的输出(我突出显示了违规行的部分).

i want to format the output of pylint myself, so i'm calling pylint.lint.Run directly, and receiving callbacks to my add_message method. pretty smooth process, but i need the column offset for the messages to build my output (i'm highlighting sections of the offending lines).

pylint 在适当的情况下报告每条消息的行号.但是,pylint 似乎没有报告任何偏移信息 - 因此它没有报告检测到问题的行中的哪个位置.在底层 pylint 使用 logilab 的另一个库,称为 astng,它是对 python 的 _ast 的更新._ast 解析节点包括偏移信息,但这似乎没有在 astng 中复制.

pylint reports the line number of each message, where appropriate. however, it seems that pylint does not report any offset information - so it isn't reporting where in the line the problem was detected. under the hood pylint uses another library from logilab, called astng, which is an update to python's _ast. _ast parse nodes include offset information, but this doesn't seem to be replicated in astng.

推荐答案

原来 astng 是基于 ast 构建的,logilab 的人给了我关于如何修补 astng 和 pylint 以获得偏移量的说明.附有补丁的门票链接:astng:http://www.logilab.org/ticket/69217?=primary&_cwmsgid=091770639ada4996a455c48aa1eb70b3pylint:http://www.logilab.org/ticket/69220=primary&_cwmsgid=0660d106aa764a4189b1f4f1faa8aa82

turns out that astng is built on ast, and the guys at logilab gave me instructions on how to patch both astng and pylint to get the offsets. links to the tickets with patches attached: astng: http://www.logilab.org/ticket/69217?vid=primary&_cwmsgid=091770639ada4996a455c48aa1eb70b3 pylint: http://www.logilab.org/ticket/69220?vid=primary&_cwmsgid=0660d106aa764a4189b1f4f1faa8aa82

这篇关于如何检索 pylint 消息的列偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆