lambda函数中的未定义变量

Ste*_*ven 3 python pylint pyspark

我有代码:

from functools import reduce

public_ids = [1,2,3,4,5]
filepath = '/path/to/file/'

rdd = sc.textFile(
    filepath
)

new_rdd = reduce(
    lambda a, b: a.filter(
        lambda x: b not in x
    ),
    public_ids,
    rdd
)
Run Code Online (Sandbox Code Playgroud)

此代码假定根据id列表过滤rdd中的行.rdd是使用spark context sc的textFile方法从位于filepath中的文件创建的.

此代码工作正常,但是pylint会引发错误:

E:未定义变量'b'(未定义变量)

我相信我编码它的方式不是正确的方法.如何更改它,以便pylint不会再次引发错误?或者它只是一个pylint无法正确识别的结构?

gta*_*ico 6

很可能这是pylint中的一个错误.

这是2年前的类似错误报告

foo = lambda x: lambda: x + 1 print(foo(1)())

在运行时正确打印2,但是pylint错误地报告

E: 1,24: Undefined variable 'x' (undefined-variable)

这是pylint 1.4.x的回归.

这里是一个最近的问题,汇报2018年11月14日同样的问题

该问题已在#760报告并由#2274修正.但是,修复程序只合并到pylint 2.x中,它只支持python> = 3.4,而我们在python 2的pylint 1.x系列中没有解决这个bug.

编辑

看起来你的误报可能与上面的问题略有不同,但是,我仍然认为这是一个错误.

我会尝试在他们的回购中创建一个问题,看看会发生什么(如果您决定这样做,请在评论中发布链接,以便我们可以关注它.)