pylint 争论带有赋值表达式的三元运算符
pylint argues about ternary operator with assignment expression
我有一些这样的代码:
return (
(1 / a)
if (a := foo())
else 0
)
我的 pylint 对此争论不休,因为 "Using variable 'a' before assignment",即使评估顺序也应该是先 a := foo()
然后 1 / a
或 0
。我试过了pip install --upgrade pylint
,但是pylint好像还是不同意这个。
好的,我发现这是 Pylint 的问题:
https://github.com/PyCQA/pylint/issues/3347
"pylint can parse the walrus operator but we haven't actually implemented support for it."(1 月 21 日)
无论如何,我会把代码修改成一些不会导致"Using variable before assignment"的等效版本,例如:
if (a := foo()):
return 1 / a
else:
return 0
我有一些这样的代码:
return (
(1 / a)
if (a := foo())
else 0
)
我的 pylint 对此争论不休,因为 "Using variable 'a' before assignment",即使评估顺序也应该是先 a := foo()
然后 1 / a
或 0
。我试过了pip install --upgrade pylint
,但是pylint好像还是不同意这个。
好的,我发现这是 Pylint 的问题:
https://github.com/PyCQA/pylint/issues/3347
"pylint can parse the walrus operator but we haven't actually implemented support for it."(1 月 21 日)
无论如何,我会把代码修改成一些不会导致"Using variable before assignment"的等效版本,例如:
if (a := foo()):
return 1 / a
else:
return 0