简体   繁体   English

PyLint错误地说一个对象缺少某些属性

[英]PyLint wrongly says an object missing certain attributes

In my code I use object from compiled extensions (in my case, igraph ). 在我的代码中,我使用来自已编译扩展名的对象(在我的情况下为igraph )。 I use PyLint to analyze the code. 我使用PyLint分析代码。 PyLint complains about missing attributes (such as igraph's Graph.adjacent ), while it clearly exists (the code runs without errors). PyLint抱怨缺少属性(例如igraph的Graph.adjacent ),而属性却明确存在(代码运行没有错误)。 What might be the cause for this messages? 此消息可能是什么原因?

Here is some test code 这是一些测试代码

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

And this is the output of pylint: 这是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 is in my PYTHONPATH PS:IGRAPH 我的PYTHONPATH

if it is a compiled C extension, there is little Pylint can do, as it cannot analyze the source code. 如果它是已编译的C扩展,则Pylint几乎无能为力,因为它无法分析源代码。 Can you print igraph.Graph.are_connected in an interactive shell ? 您可以在交互式外壳中打印igraph.Graph.are_connected吗? If not, it means that the library probably does some weird things at instantiation time or that the methods are introspected. 如果不是,则意味着该库可能在​​实例化时做了一些奇怪的事情,或者这些方法是自省的。

In any case this is a tricky problem for pylint. 无论如何,这对于pylint来说是一个棘手的问题。

You could use the patch provided on http://www.logilab.org/ticket/73978 (recently included in the dev tree) or ignore E1101 with inlined directives. 您可以使用http://www.logilab.org/ticket/73978 (最近包含在开发树中)提供的补丁,也可以使用内联指令忽略E1101。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM