Skip to content

Conversation

@PaulRenvoise
Copy link
Contributor

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

This PR reduce the scope of len-as-condition to only care when a len(SEQUENCE) call is made without an explicit comparison. As stated in PEP8:

For sequences, (strings, lists, tuples), use the fact that empty sequences are false.

It also changes the checker's message and description to:

Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length to a scalar.

Type of Changes

Type
🐛 Bug fix
🔨 Refactoring

Related Issue

Closes #2684

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 89.713% when pulling b2cd28a on PaulRenvoise:fix/len_as_condition into 095928c on PyCQA:master.

@PCManticore PCManticore merged commit 4714a65 into pylint-dev:master Mar 19, 2019
@PCManticore
Copy link
Contributor

Thanks a lot for your PR @PaulRenvoise ! It was super clean and straightforward. 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow len-as-condition for explicit comparison

3 participants