Python 2to3 警告<你应该在这里使用'operator.mul(None)'>这是什么意思?



我正在使用2to3转换脚本。我唯一得到的警告是:

RefactoringTool: Line 716: You should use 'operator.mul(None)' here.

原始脚本的第716行是:

classes = repeat(None)

我不明白在哪里使用operator.mul(None)repeat()的参考文档(链接到文档(表明我可以通过None毫无问题。那么,我该怎么办?

2to3只是对您的意思是哪种repeat感到困惑。它认为您在Python 2中使用operator.repeat

Help on built-in function repeat in module operator:
repeat(...)
    repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.

而不是itertools.repeat。老实说,这对它而言并不是一个很好的猜测,因为operator.repeat进行了2个论点,但这就是它的猜测。您可以看到文档中列出的转换。

您可以使用完全合格的itertools.repeat避免警告或忽略它。

最新更新