pylint-bot / pylint-unofficial

UNOFFICIAL playground for pylint github migration
0 stars 0 forks source link

Pylint 1.5: __iterator__ returns non-iterator error for file #691

Closed pylint-bot closed 8 years ago

pylint-bot commented 9 years ago

Originally reported by: Pedro Rodriguez (BitBucket: pedrorodriguez, GitHub: @pedrorodriguez?)


I have the following code that is being run through pylint:

class LazyFile(object):
    # pylint: disable=too-few-public-methods,too-many-instance-attributes
    def __init__(self, path, delimiter=None, mode='r', buffering=-1, encoding=None,
                 errors=None, newline=None):
        # pylint: disable=too-many-arguments
        self.path = path
        self.delimiter = delimiter
        self.mode = mode
        self.buffering = buffering
        self.encoding = encoding
        self.errors = errors
        self.newline = newline
        self.file = None

    def __iter__(self):
        if self.file is not None:
            self.file.close()
        self.file = builtins.open(self.path, mode=self.mode, buffering=self.buffering,
                                  encoding=self.encoding, errors=self.errors, newline=self.newline)
        return self.file

And gives this error: E: 72, 4: __iter__ returns non-iterator (non-iterator-returned)

This seems wrong given that a file is its own iterator (that is, iter(file)=file.


pylint-bot commented 9 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Thank you for the report.

pylint-bot commented 9 years ago

Original comment by BitBucket: dmand, GitHub: @dmand?:


Should be fixed by df18ac7d2dca.