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.

Add the `iter()` builtin to checker `C407`

See original GitHub issue

iter()

Example:

even_iterator = iter([i for i in range(1,100) if i%2 == 0])

This can be directly written as:

even_iterator = iter(i for i in range(1,100) if i%2 == 0)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
joaoecommented, Jan 20, 2020

I’m closing this issue, since it’s not generally safe due to the change in possible raised exception from IndexError to StopIteration.

#59 deals with <expr>[0]. This issue is just about a plain iter, which always raises a StopIteration when empty.

>>> next(iter([1 for _ in ""]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration
>>> next(1 for _ in "")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration
0reactions
adamchainzcommented, Jan 20, 2020

You’re right!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python iter() (With Examples) - Programiz
In this tutorial, you will learn about the Python iter() with the help of examples. The iter() method returns an iterator for the...
Read more >
itertools — Functions creating iterators for efficient looping ...
This module implements a number of iterator building blocks inspired by constructs from APL, Haskell, and SML. Each has been recast in a...
Read more >
How does the built-in function iter() convert a Python list to an ...
I check a list and find it has no __next__ method. When using iter() on it, it will become an iterator. Does this...
Read more >
4. Iterators and Generators - Python Cookbook, 3rd ... - O'Reilly
The use of the iter() function here is a bit of a shortcut that cleans up the code. iter(s) simply returns the underlying...
Read more >
Python iter() function - w3resource
The iter() function returns an iterator object. Version: (Python 3.2.5). Syntax: ... Python: Built-in-function - iter() function.
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