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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect redundant enumerate #1825

Closed
orsinium opened this issue Jan 19, 2021 · 8 comments 路 Fixed by #2213
Closed

Detect redundant enumerate #1825

orsinium opened this issue Jan 19, 2021 · 8 comments 路 Fixed by #2213
Assignees
Labels
help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule
Milestone

Comments

@orsinium
Copy link
Collaborator

orsinium commented Jan 19, 2021

Rule request

Thesis

# bad
for _, item in enumerate(items):
  ...

# good
for item in items:
  ...

Reasoning

Simplification.

P.S. I'm not making it, have seen it in the wild 馃檭

@orsinium orsinium added the rule request Adding a new rule label Jan 19, 2021
@orsinium
Copy link
Collaborator Author

orsinium commented Jan 19, 2021

The same can be applied to dict.items but it apparently requires to know the right type for the iterator. Probably, one more good candidate for typed-linter.

dctnr = {1: 2, 3: 4}
for _, value in dctnr.items():
  ...
for key, _ in dctnr.items():
  ...

@sobolevn
Copy link
Member

sobolevn commented Feb 6, 2021

I will leave this one for typed-linter.

@sobolevn sobolevn closed this as completed Feb 6, 2021
@orsinium
Copy link
Collaborator Author

orsinium commented Feb 8, 2021

It will be false-positive only if you have shadowed enumerate function, and I'd say it is a bad practice on its own and you deserve this false-positive then 馃檭

@sobolevn sobolevn reopened this Feb 8, 2021
@sobolevn
Copy link
Member

sobolevn commented Feb 8, 2021

Yes, my bad!

I was confused by:

dctnr = {1: 2, 3: 4}
for _, value in dctnr.items():
  ...
for key, _ in dctnr.items():
  ...

This should go to typed-linter rule.

@sobolevn sobolevn added this to the Version 0.16 milestone Feb 8, 2021
@sobolevn sobolevn added help wanted Extra attention is needed level:starter Good for newcomers labels Feb 8, 2021
@ujju20
Copy link

ujju20 commented May 18, 2021

Hello, I am a beginner in the Open source world and I found this issue to be good first so I would like to take this issue. So please guide me.

@sobolevn
Copy link
Member

Hi @ujju20!

Make sure to read our contributing guides

Next, you will need to create a new violation and a new visitor, see our glossary what these things mean.

I am here to help: ask anything you need.

@lensvol
Copy link
Collaborator

lensvol commented Oct 3, 2021

If this is not taken by anybody, can I take it over?

@sobolevn sobolevn assigned lensvol and unassigned ujju20 Oct 3, 2021
@orsinium
Copy link
Collaborator Author

orsinium commented Oct 4, 2021

Sure, go on :)

lensvol added a commit that referenced this issue Oct 6, 2021
sobolevn pushed a commit that referenced this issue Oct 7, 2021
* Add 'redundant enumerate()' violation.

Closes #1825

* Simplify type signature for RedundantEnumerateVisitor using AnyFor.

* Add proper processing of comprehensions and generator expressions to 'RedundantEnumerateVisitor'.

* Revert unrelated change to a test snapshot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants