pandas 禁用 Pylint no member-特定库的 E1101 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33961756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:17:00  来源:igfitidea点击:

Disabling Pylint no member- E1101 error for specific libraries

pandaspylint

提问by Michael WS

Is there anyway to hide E1101errors for objects that are created from a specific library? Our large repository is littered with #pylint: disable=E1101around various objects created by pandas.

无论如何隐藏E1101从特定库创建的对象的错误?我们的大型存储库中散落着#pylint: disable=E1101由 Pandas 创建的各种对象。

For example, pylint will throw a no member error on the following code:

例如,pylint 将在以下代码中抛出 no member 错误:

import pandas.io.data
import pandas as pd
spy = pandas.io.data.DataReader("SPY", "yahoo")
spy.to_csv("test.csv")
spy = pd.read_csv("test.csv")
close_px = spy.ix["2012":]

Will have the following errors:

会出现以下错误:

E:  6,11: Instance of 'tuple' has no 'ix' member (no-member)
E:  6,11: Instance of 'TextFileReader' has no 'ix' member (no-member)

采纳答案by carabas

You can mark their attributes as dynamically generated using generated-membersoption.

您可以使用generated-members选项将它们的属性标记为动态生成。

E.g. for pandas:

例如对于Pandas:

generated-members=pandas.*

回答by user10261978

This failed for me trying to ignore errors in numpy, until I tried

这对我试图忽略 numpy 中的错误失败了,直到我尝试

generated-members=np.*

since, like most everybody, I do

因为,像大多数人一样,我做

import numpy as np

Since generated-members takes a list, one might do:

由于生成成员需要一个列表,因此可能会这样做:

generated-members=numpy.*,np.*

回答by Xavier Lamorlette

Additional information, on top of the answer from carabas:

附加信息,除了来自 carabas 的回答之外:

You will find generated-membersin the TYPECHECKsection of .pylintrc.
Here is the default one:

您将generated-membersTYPECHECK部分找到.pylintrc
这是默认的:

[TYPECHECK]
…
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed.
generated-members=REQUEST,acl_users,aq_parent

Note that the comment about suppressing E0201 is incomplete.
So you have to update this to:

请注意,关于抑制 E0201 的评论是不完整的。
因此,您必须将其更新为:

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 or E1101 when accessed.
generated-members=REQUEST,acl_users,aq_parent,pandas.*