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 new checker len-as-condition #1154

Merged
merged 2 commits into from Nov 30, 2016

Conversation

Projects
None yet
4 participants
@atodorov
Contributor

atodorov commented Nov 1, 2016

This new checker implements the following statement from PEP8:

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

Yes: if not seq:
     if seq:

No: if len(seq):
    if not len(seq):

This is still a work in progress mainly around lines 76-79 when we have a Compare statement. ATM I'm not handling statements like 0 < len(S) < 5 or 0 != len(S), etc. Advice is welcome on how to handle this and what sort of error conditions to consider valid.

Background: Recently I've been working with a code base which has lots of if len(something) > 0 or if len(something) != 0 and figured I'll write this patch.

@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Nov 2, 2016

Contributor

NOTE: I'm also not sure how to fix the remaining pylint warnings. Need a hint.

Contributor

atodorov commented Nov 2, 2016

NOTE: I'm also not sure how to fix the remaining pylint warnings. Need a hint.

@rogalski

This comment has been minimized.

Show comment
Hide comment
@rogalski

rogalski Nov 6, 2016

Contributor

@atodorov what's unclear with pylint errors? Your new checker simply found these violations in current pylint source. https://github.com/PyCQA/pylint/blob/master/pylint/config.py#L175 is one of errors, I'm sure rest follow the same pattern.

Contributor

rogalski commented Nov 6, 2016

@atodorov what's unclear with pylint errors? Your new checker simply found these violations in current pylint source. https://github.com/PyCQA/pylint/blob/master/pylint/config.py#L175 is one of errors, I'm sure rest follow the same pattern.

@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Nov 8, 2016

Contributor

@rogalski thanks for the hint. I thought the pylint errors were somewhere in the code I wrote and didn't realize the new checker will run against the rest of the project. I've finalized the len_cherker, added some more tests and also updated the rest of the project where the new checker complained.

This PR is ready for review.

Contributor

atodorov commented Nov 8, 2016

@rogalski thanks for the hint. I thought the pylint errors were somewhere in the code I wrote and didn't realize the new checker will run against the rest of the project. I've finalized the len_cherker, added some more tests and also updated the rest of the project where the new checker complained.

This PR is ready for review.

@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Nov 16, 2016

Contributor

ping, any updates on this one ?

Contributor

atodorov commented Nov 16, 2016

ping, any updates on this one ?

@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Nov 23, 2016

Contributor

This is ready to be merged, please review.

Contributor

atodorov commented Nov 23, 2016

This is ready to be merged, please review.

@PCManticore

This comment has been minimized.

Show comment
Hide comment
@PCManticore

PCManticore Nov 23, 2016

Member

I didn't have time lately for doing a thorough review. In general, it looks good, but I will get back with a more thorough analysis in the following days.

Member

PCManticore commented Nov 23, 2016

I didn't have time lately for doing a thorough review. In general, it looks good, but I will get back with a more thorough analysis in the following days.

@rowillia

Good stuff! I'm excited to get a chance to use this!

Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/test/functional/len_checks.py
Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
if len(S) == 0:
pass

This comment has been minimized.

@rowillia

rowillia Nov 23, 2016

Contributor

Consider adding an example of how to correctly handle this and linking to https://www.python.org/dev/peps/pep-0008/#programming-recommendations for our less experienced python developer friends 😄

@rowillia

rowillia Nov 23, 2016

Contributor

Consider adding an example of how to correctly handle this and linking to https://www.python.org/dev/peps/pep-0008/#programming-recommendations for our less experienced python developer friends 😄

This comment has been minimized.

@atodorov

atodorov Nov 23, 2016

Contributor

added

@atodorov

atodorov Nov 23, 2016

Contributor

added

@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Nov 23, 2016

Contributor

@rowillia thanks for the review. I'm working my way through the comments and will reply where necessary.

Contributor

atodorov commented Nov 23, 2016

@rowillia thanks for the review. I'm working my way through the comments and will reply where necessary.

Show outdated Hide outdated doc/whatsnew/2.0.rst
Show outdated Hide outdated pylint/checkers/len.py
@PCManticore

This comment has been minimized.

Show comment
Hide comment
@PCManticore

PCManticore Nov 24, 2016

Member

Looks pretty nice. Left a couple of minor comments.

Member

PCManticore commented Nov 24, 2016

Looks pretty nice. Left a couple of minor comments.

Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
Show outdated Hide outdated pylint/checkers/len.py
@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Nov 24, 2016

Contributor

@PCManticore - thanks for the review, updated and merged with refactoring.py

Contributor

atodorov commented Nov 24, 2016

@PCManticore - thanks for the review, updated and merged with refactoring.py

@rowillia

@atodorov Looks great! Couple more small nits. Most important bit is making sure we get the category correct.

The pypy failure looks unrelated, but kicking this PR with those fixes should help us be sure 😄

Show outdated Hide outdated doc/whatsnew/2.0.rst
Show outdated Hide outdated pylint/checkers/refactoring.py
Show outdated Hide outdated pylint/checkers/refactoring.py
Show outdated Hide outdated pylint/checkers/refactoring.py
Show outdated Hide outdated pylint/checkers/refactoring.py
@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Nov 29, 2016

Contributor

@rowillia updated & rebased

Contributor

atodorov commented Nov 29, 2016

@rowillia updated & rebased

@rowillia

This comment has been minimized.

Show comment
Hide comment
@rowillia

rowillia Nov 30, 2016

Contributor

@atodorov Great, Thanks! Appveyor failure looks unrelated.

Contributor

rowillia commented Nov 30, 2016

@atodorov Great, Thanks! Appveyor failure looks unrelated.

@rowillia rowillia merged commit 4ba1660 into PyCQA:master Nov 30, 2016

2 of 3 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.04%) to 90.626%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment