-
-
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
Add checker for comparing for equality to empty literal #4774
Comments
I already though of a way to implement it, but couldn't yet think of a good name or description. If anyone once to take a stab at it, this here should work: def visit_compare(self, node: astroid.Compare) -> None:
for op, comparator in node.ops:
if op == "==":
if (
isinstance(comparator, (astroid.List, astroid.Tuple))
and not comparator.elts
or isinstance(comparator, astroid.Dict)
and not comparator.items
):
self.add_message(..., node=node) |
Perhaps |
Sounds like a start. I'm not good at naming things though 😅
Maybe a small performance effect and a bit code style. So probably a |
Maybe |
I've been thinking: we could rename |
Probably should also implement #3031 when working on this issue. |
Hi, can I try to resolve this issue? |
Hi, @jaehoonhwang , of course, I'll assign you to the issue. |
* Create a new visitor on refactoring_checker; `visit_compare` * Create a new checker; use-implicit-booleanness checker where it looks for boolean evaluatiion with collection literals such as `()`, `[]`, or `{}` * Fixed invalid usage of comparison within pylint package This closes pylint-dev#4774
* Create a new visitor on refactoring_checker; `visit_compare` * Create a new checker; use-implicit-booleanness checker where it looks for boolean evaluatiion with collection literals such as `()`, `[]`, or `{}` * Fixed invalid usage of comparison within pylint package This closes pylint-dev#4774
Rename `len-as-condition` to be more general for new checker `use-implicit-booleaness-not-comparison` Closes pylint-dev#4774 * Refactor `LenChecker` class -> `ImplicitBooleanessChecker`o * Rename test files/`len_checker.py`/`__init__.py` to reflect new name. * Add `len-as-condition` as `old_names` for `use-implicit-booleaness-not-len`
* Create a new visitor on refactoring_checker; `visit_compare` * Create a new checker; use-implicit-booleanness checker where it looks for boolean evaluatiion with collection literals such as `()`, `[]`, or `{}` * Fixed invalid usage of comparison within pylint package This closes pylint-dev#4774
* Create a new visitor on refactoring_checker; `visit_compare` * Create a new checker; use-implicit-booleanness checker where it looks for boolean evaluatiion with collection literals such as `()`, `[]`, or `{}` * Fixed invalid usage of comparison within pylint package This closes pylint-dev#4774
* Create a new visitor on refactoring_checker; `visit_compare` * Create a new checker; use-implicit-booleanness checker where it looks for boolean evaluatiion with collection literals such as `()`, `[]`, or `{}` * Fixed invalid usage of comparison within pylint package This closes pylint-dev#4774
…on with collection literals (#5120) * Create a new checker; use-implicit-booleanness checker where it looks for boolean evaluatiion with collection literals such as `()`, `[]`, or `{}` * Fixed invalid usage of comparison within pylint package This closes #4774 * Ignore tuples when checking for `literal-comparison` Closes #3031 * Merge len_checker with empty_literal checker Moving empty literal checker with len_checker to avoid class without iterators without boolean expressions (false positive on pandas) Reference: https://github.com/PyCQA/pylint/pull/3821/files * Update `len_checker` and its class `LenChecker` to `ComparisonChecker` to reflect better usage after merging between `len_checker` and `empty_literal_checker` and its tests. * Fixed `consider_using_in` and `consider_iterating_dictionary` tests that were failing due to new empty literal checkers. Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Pylint 2.12.0 introduced new checker: > Used when Pylint detects that collection literal comparison is being used to check for emptiness; Use implicit booleaness insteadof a collection classes; empty collections are considered as false See pylint-dev/pylint#4774 Fixes: fleet-commander#279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Pylint 2.12.0 introduced new checker: > Used when Pylint detects that collection literal comparison is being used to check for emptiness; Use implicit booleaness insteadof a collection classes; empty collections are considered as false See pylint-dev/pylint#4774 Fixes: fleet-commander#279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Pylint 2.12.0 introduced new checker: > Used when Pylint detects that collection literal comparison is being used to check for emptiness; Use implicit booleaness insteadof a collection classes; empty collections are considered as false See pylint-dev/pylint#4774 Fixes: #279 Signed-off-by: Stanislav Levin <slev@altlinux.org>
Current problem
Originally posted by @cdce8p in #4769 (comment)
Best not to check for equality by comparing it to an empty literal.
(This should probably be a pylint check as well.)
Desired solution
Additional context
No response
The text was updated successfully, but these errors were encountered: