PyLint 错误地表示对象缺少某些属性

发布于 2024-12-02 04:47:34 字数 972 浏览 2 评论 0原文

在我的代码中,我使用编译扩展中的对象(在我的例子中,igraph)。我使用 PyLint 来分析代码。 PyLint 抱怨缺少属性(例如 igraph 的 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 is in my PYTHONPATH

In my code I use object from compiled extensions (in my case, igraph). I use PyLint to analyze the code. PyLint complains about missing attributes (such as igraph's Graph.adjacent), while it clearly exists (the code runs without errors). 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:

************* 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2024-12-09 04:47:34

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

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

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

if it is a compiled C extension, there is little Pylint can do, as it cannot analyze the source code. Can you print igraph.Graph.are_connected in an interactive shell ? 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文