I have some code like this:
return (
(1 / a)
if (a := foo())
else 0
)
My pylint argues about this because "Using variable 'a' before assignment", even the evaluation order should be a := foo()
first and then 1 / a
or 0
. I tried pip install --upgrade pylint
, but it seems that pylint still do not agree this.
OK, I find that this is an issue of Pylint:
https://github.com/PyCQA/pylint/issues/3347
"pylint can parse the walrus operator but we haven't actually implemented support for it." (21 Jan)
Anyway, I will modify the code to some equivalent versions which do not cause "Using variable before assignment", for example:
if (a := foo()):
return 1 / a
else:
return 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.