question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WPS122 should allow a no-op loop var

See original GitHub issue

Bug report

What’s wrong

Imagine I want to do something 3 times but I don’t care about the attempt number. So I’d normally write something like this:

for _ in range(3):
    do_something()

But then the linter complains with WPS122 Found all unused variables definition: _ which is incorrect. While things like assignment allow to fix this with

-_something_unused = get_useless_result()
+get_useless_result()

it is impossible with for-loops not to define this loop variable at all.

How is that should be

This case shouldn’t be a violation of the given rule.

System information

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
sobolevncommented, Sep 12, 2020

It is not released. Will be released in 0.15

1reaction
sobolevncommented, May 18, 2020

The same applies for comprehensions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get around declaring an unused variable in a for ...
The special case being loops not using the items of the thing being iterated and the rule being that there's a "target" to...
Read more >
tensorflow/control_flow.py at master - autograph - GitHub
get_state/set_state allow piping the mutations through the loop variables as ... self_x = self.x # write self.x back into the loop vars. return...
Read more >
For-Loops - Python Numerical Methods
A for-loop assigns the looping variable to the first element of the sequence. It executes everything in the code block. Then it assigns...
Read more >
Go: Redefining For Loop Variable Semantics | Hacker News
i would always be equal to 9. With let instead of var, i is properly scoped and the executed script display each increment...
Read more >
for loops — Geo-Python site documentation
Loops allow parts of code to be repeated some number of times. ... The variable can be any name you like, and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found