-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive expression-not-assigned
when calling functions with no return inside ternary expression
#8129
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
If it is re-written as the following, the message goes away; so I think it makes sense for consistency to consider the one-line version a false positive: if test:
f1()
else:
f2() |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
expression-not-assigned
when calling functions with no return inside ternary expression
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Looking into the origins of the conditional expression and it looks like I don't see anything specifically stating that it must be assigned to a name; although the real-world code examples in the link mostly are assigning to a name. PEP308 |
There are at least four ways to deal with this warning.
# if / else blocks
if test:
f1()
else:
f2()
_ = f1() if test else f2()
(f1 if test else f2)()
# pylint: disable = expression-not-assigned
f1() if test else f2() If a one-liner is desired, I suggest going with option 3. But in any case I don't think any changes ought to be made to Pylint to accommodate the original. One coder's false positive is another's false negative. |
|
Bug description
Configuration
No response
Command used
Pylint output
test.py:9: [W0106(expression-not-assigned), ] Expression "f1() if test else f2()" is assigned to nothing
Expected behavior
no warning (according to documentation of pylint)
Pylint version
OS / Environment
windows
The text was updated successfully, but these errors were encountered: