Skip to content
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

Pylint should not report literal-comparison when testing for tuple #3031

Closed
chaoflow opened this issue Jul 28, 2019 · 3 comments · Fixed by #5120
Closed

Pylint should not report literal-comparison when testing for tuple #3031

chaoflow opened this issue Jul 28, 2019 · 3 comments · Fixed by #5120
Labels
Milestone

Comments

@chaoflow
Copy link

Steps to reproduce

def foo(bar=()):
    if bar is not ():
        ...

Current behavior

pylint reports "literal-comparison"

Expected behavior

pylint should regard the "is (not)" comparison correctly.

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.3 (default, Apr  3 2019, 19:16:38) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
@PCManticore
Copy link
Contributor

Yeah, we can probably exempt tuples from the check.

@chaoflow chaoflow changed the title Pylint should not report literal-comparison when testing for empty tuple Pylint should not report literal-comparison when testing for tuple Jul 29, 2019
@chaoflow
Copy link
Author

@PCManticore I think it's noteworthy that only starting with Python 3.7 (1,) is (1,) before this was only true for the empty tuple.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.12.0 milestone Oct 10, 2021
jaehoonhwang added a commit to jaehoonhwang/pylint that referenced this issue Oct 11, 2021
Pierre-Sassoulas added a commit that referenced this issue Oct 17, 2021
…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 <[email protected]>
@chaoflow
Copy link
Author

Following up on this, I think only the empty tuple should be exempted.

compare

tuple(range(0)) is ()
tuple(range(1)) is (0,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants