-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
PLC1901 false positive in __bool__
methods
#4282
Comments
Yeah, The "safe" fix for this rule should probably be |
In one case I specifically need the comparison :) |
I dislike this rule, too many false positives. |
This rule is fundamentally incorrect for assertions or assignments, since
Command: Output:
|
Yes, Pylint's implementation has the same problem: ❯ pylint --load-plugins=pylint.extensions.emptystring foo.py
************* Module foo
foo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
foo.py:1:0: C0104: Disallowed name "foo" (disallowed-name)
foo.py:1:0: C0103: Constant name "a" doesn't conform to UPPER_CASE naming style (invalid-name)
foo.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)
foo.py:4:11: C1901: "a == ''" can be simplified to "not a" as an empty string is falsey (compare-to-empty-string) I'm going to move this rule to the nursery so that it's explicitly opt-in. |
## Summary This rule has too many false positives. It has parity with the Pylint version, but the Pylint version is part of an [extension](https://pylint.readthedocs.io/en/stable/user_guide/messages/convention/compare-to-empty-string.html), and so requires explicit opt-in. I'm moving this rule to the nursery to require explicit opt-in, as with Pylint. Closes #4282.
Looks like the rule was renamed/revisited: |
Here's another example where this rule creates false positives with import numpy as np
array = np.array(("X", "", "X"), dtype=str)
indices = array == ""
print(indices)
print(not array) At least in this case, |
Trying to correct this to
self.val
will lead to an error:The text was updated successfully, but these errors were encountered: