1

在我的代码中,我使用来自已编译扩展的对象(在我的例子中是igraph)。我使用 PyLint 来分析代码。PyLint 抱怨缺少属性(例如 igraph's Graph.adjacent),而它显然存在(代码运行时没有错误)。出现此消息的原因可能是什么?

这是一些测试代码

import igraph
gr = igraph.Graph(10)#create a graph with 10 vertices
edges = gr.es #no pylint errors
vertices = gr.vs #no pylint errors
print gr.are_connected(0, 1) #pylint error E1101
print gr.adjacent(0) #pylint error E1101

这是 pylint 的输出:

************* Module temp
C0111:  1: Missing docstring
C0103:  2: Invalid name "gr" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C0103:  3: Invalid name "edges" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C0103:  4: Invalid name "vertices" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
E1101:  5: Instance of 'Graph' has no 'are_connected' member
E1101:  6: Instance of 'Graph' has no 'adjacent' member

PS:igraph我的 PYTHONPATH 中

4

1 回答 1

1

如果是编译的 C 扩展,Pylint 几乎无能为力,因为它无法分析源代码。您可以在交互式外壳中打印 igraph.Graph.are_connected 吗?如果不是,则意味着该库可能在​​实例化时做了一些奇怪的事情,或者这些方法是自省的。

无论如何,这对 pylint 来说都是一个棘手的问题。

您可以使用http://www.logilab.org/ticket/73978上提供的补丁(最近包含在开发树中)或使用内联指令忽略 E1101。

于 2011-08-30T09:50:23.600 回答