我如何检索 pylint 消息的列偏移量?
我想自己格式化 pylint 的输出,所以我直接调用 pylint.lint.Run ,并接收对我的 add_message 方法的回调。过程非常顺利,但我需要消息的列偏移量来构建我的输出(我突出显示有问题的行的部分)。
pylint 在适当的情况下报告每条消息的行号。然而, pylint 似乎没有报告任何偏移量信息 - 因此它没有报告检测到问题的行中的位置。 pylint 在底层使用了 logilab 的另一个库,名为 astng,它是 python _ast 的更新。 _ast 解析节点包含偏移量信息,但这似乎没有在 astng 中复制。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,astng 是建立在 ast 之上的,logilab 的人给了我如何修补 astng 和 pylint 以获得偏移量的说明。附有补丁的门票链接:
astng: http://www.logilab.org/ticket/69217?vid=primary&_cwmsgid=091770639ada4996a455c48aa1eb70b3
pylint: http://www.logilab.org/ticket/69220?vid=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