4
votes

When I'm typing something like this in PyCharm IDE 3.0.2 Community Edition (Python 2.7.x):

directory = '/home/user/dir'
samples_list = os.walk(directory).next()[1]

I get warning in IDE Unresolved attribute reference 'next' for class 'Iterable'.

So, I want to know if this is error because of IDE (http://youtrack.jetbrains.com/issue/PY-11401) or I should do something with my code.

UPD1: Unfortunately, this is a bug in Pycharm PY-12017

1
Are you sure these are the lines instigating the error? os.walk(directory) is of type generator, not Iterable (and there is no class called Iterable in the standard library.) - unutbu
Yep, this line is highlighted in IDE and .next() part is highlighted too. - silent
@MartijnPieters: yes, but why would PyCharm capitalize Iterables as though it were the name of the class? - unutbu
@unutbu: Most likely it is using the collections abstract base class - Martijn Pieters

1 Answers

6
votes

Your IDE is incorrect, in Python 2 iterators (including generators like os.walk()) do have a .next() method.

You can also use the built-in next() function:

samples_list = next(os.walk(directory))[1]

I suspect the IDE mismatched the generator against the collections.Iterable ABC, while generators are Iterators too.