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

New checker - Detect use of unnecessary ellipsis #5470

Merged

Conversation

mbyrnepr2
Copy link
Member

Closes #5460

Emit a warning when ... is used and could be omitted. Similar to the unnecessary-pass checker.

Type of Changes

Type
πŸ› Bug fix
βœ“ ✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Description

Closes #5460

@coveralls
Copy link

coveralls commented Dec 4, 2021

Pull Request Test Coverage Report for Build 1574520196

  • 15 of 15 (100.0%) changed or added relevant lines in 1 file are covered.
  • 41 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.005%) to 93.661%

Files with Coverage Reduction New Missed Lines %
pylint/testutils/functional/test_file.py 1 96.36%
pylint/testutils/lint_module_test.py 12 85.63%
pylint/checkers/variables.py 28 95.63%
Totals Coverage Status
Change from base Build 1572908427: 0.005%
Covered Lines: 14198
Relevant Lines: 15159

πŸ’› - Coveralls

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Dec 4, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Dec 4, 2021
@mbyrnepr2 mbyrnepr2 force-pushed the 5460_checker_unnecessary_ellipsis branch from 9e4db96 to a285bc3 Compare December 7, 2021 14:49
@mbyrnepr2 mbyrnepr2 marked this pull request as ready for review December 8, 2021 10:23
@Pierre-Sassoulas Pierre-Sassoulas added the Checkers Related to a checker label Dec 8, 2021
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@Pierre-Sassoulas
Copy link
Member

Well except the fact it's in the string checker, it's not really related to strings, right ?

@Pierre-Sassoulas Pierre-Sassoulas dismissed their stale review December 8, 2021 21:57

Did not check where the code was added

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a quick look and want to interrupt before @Pierre-Sassoulas might merge this:

Expected output of the tests is incorrect as it is missing the end line and column. This is because node is not being passed to add_message. This should be done!

@Pierre-Sassoulas This is something for future reviews as well: node should be made mandatory (is on my todo list) but that requires some work. In the meantime we should require it for most new PRs.

@Pierre-Sassoulas
Copy link
Member

node should be made mandatory (is on my todo list) but that requires some work.

You're right, my bad. Isn't that another breaking change for 3.0 ?

@DanielNoord
Copy link
Collaborator

You're right, my bad. Isn't that another breaking change for 3.0 ?

Yeah! But adding a DeprecationWarning now would make us trigger it ourself. I'd like to fix that before doing so.

Just to let you know, I currently plan to first fix unittests and then fix statement(). After this it's back to typing PyLinter in terms of maintenance.
I'll do some simpler crash/bug fixes in between. :)

1 similar comment
@DanielNoord
Copy link
Collaborator

You're right, my bad. Isn't that another breaking change for 3.0 ?

Yeah! But adding a DeprecationWarning now would make us trigger it ourself. I'd like to fix that before doing so.

Just to let you know, I currently plan to first fix unittests and then fix statement(). After this it's back to typing PyLinter in terms of maintenance.
I'll do some simpler crash/bug fixes in between. :)

@Pierre-Sassoulas
Copy link
Member

adding a DeprecationWarning now would make us trigger it ourself.

Sounds good !

@@ -2270,6 +2270,32 @@ def _check_docstring(
)


class EllipsisChecker(_BasicChecker):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a new file pylint/checker/ellipsis_checker.py, as we want to burst base.py in #5489

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for separating the checker πŸ‘

@DanielNoord DanielNoord self-requested a review December 12, 2021 08:24
@DanielNoord
Copy link
Collaborator

Note that I haven't done a full review but I think the 18 prefix is already being used. I'm on mobile so I can't link the file, but there is a script in the scripts folder that can point you to a new unused prefix.

@Pierre-Sassoulas
Copy link
Member

I think the 18 prefix is already being used

We could add a pre-commit script to check that, what do you think @DanielNoord ? Maybe based on the existing script for unused prefix.

@DanielNoord
Copy link
Collaborator

There is an open issue about this to which I assigned myself. Haven't gotten around to it because the unittests move take so much time and I think they are more important.

@mbyrnepr2
Copy link
Member Author

Thanks for the advice @Pierre-Sassoulas & @DanielNoord πŸ‘

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code itself looks good, I would only add some additional comments and explanations.

I'm also wondering if we should add a confidence level to this message.

ChangeLog Outdated Show resolved Hide resolved
pylint/checkers/ellipsis_checker.py Outdated Show resolved Hide resolved
pylint/checkers/ellipsis_checker.py Outdated Show resolved Hide resolved
tests/functional/u/unnecessary/unnecessary_ellipsis.txt Outdated Show resolved Hide resolved
- Informative Changelog, docstring & checker description
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes, much better!

I just thought of one additional test case I think we should add by default: overloads.
Could you add an example? The mypy documentation should help with coming up with a simple but effective example.

pylint/checkers/ellipsis_checker.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add checker for unnecessary ellipsis
4 participants