Bet*_*ker 5 python pylint python-2.7
我有一个 Python 应用程序,由于第三方库,我必须使用 Python 2.7,但我正在努力充分利用它。
我已经下载了 PyLint 1.9.5 并且基本上可以让它工作了。我遇到了一件事,但找不到解决方案。
我有一些课程基本上是这样的:
class Narg(object):
[snip]
class Foo(object):
def __init__(self):
self.bar = None # type: Optional[list[Narg]]
def find(self):
if self.bar:
for narg in self.bar:
[snip]
Run Code Online (Sandbox Code Playgroud)
pylint 不喜欢这个,它给了我
E:201,80: Non-iterable value self.bar is used in an iterating context (not-an-iterable)
Run Code Online (Sandbox Code Playgroud)
代码运行良好,所以它实际上很好,我怎样才能说服 pylint 呢?
pylint
无法知道self.bar
稍后可能会从存在更新None
为可迭代。因此你有 2 个选择:
self.bar
化为空可迭代 - 例如self.bar = []
self.bar = None # pylint: disable=not-an-iterable