You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggest change from next(iter(<comprehension>)) and next(iter(<generator>)) to next(<generator>) as next() will happily consume a generator. Need to be aware of the default argument to next() in which case the generator will need still to be wrapped in parentheses and the sentinel argument to iter() in which case this change cannot be recommended.
Also note that we cannot have a more generic rule for iter(<comprehension>) to <comprehension> as the type of the former is an iterator and the latter is an iterable (or collection/sequence), e.g. list vs listiterator.
This will work for list, set and tuple comprehensions as they implicitly create iterators, but not for dict.
This change could also apply in other contexts where the return of iter() is not assigned to a variable and will never be reused, e.g. sorted(iter(...)).
The text was updated successfully, but these errors were encountered:
Suggest change from
next(iter(<comprehension>))
andnext(iter(<generator>))
tonext(<generator>)
asnext()
will happily consume a generator. Need to be aware of thedefault
argument tonext()
in which case the generator will need still to be wrapped in parentheses and thesentinel
argument toiter()
in which case this change cannot be recommended.Also note that we cannot have a more generic rule for
iter(<comprehension>)
to<comprehension>
as the type of the former is an iterator and the latter is an iterable (or collection/sequence), e.g.list
vslistiterator
.This will work for
list
,set
andtuple
comprehensions as they implicitly create iterators, but not fordict
.This change could also apply in other contexts where the return of
iter()
is not assigned to a variable and will never be reused, e.g.sorted(iter(...))
.The text was updated successfully, but these errors were encountered: