From 8dfe38e9e6541185e78a25d684ca1a4a4d9695b0 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Tue, 25 Oct 2016 12:02:00 -0500 Subject: [PATCH] Fix up FileProcessor.file_tokens property We opted to not copy the file_tokens attribute each time it's accessed in the merge request discussion but it was never reflected in the code. Further, the attribute had no documentation or docstring, so we've added that. Finally, we address a personal style nit that I otherwise wouldn't have picked at. --- src/flake8/processor.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/flake8/processor.py b/src/flake8/processor.py index 0e8c153..8490092 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -103,15 +103,22 @@ class FileProcessor(object): @property def file_tokens(self): + """The complete set of tokens for a file. + + Accessing this attribute *may* raise an InvalidSyntax exception. + + :raises: flake8.exceptions.InvalidSyntax + """ if self._file_tokens is None: line_iter = iter(self.lines) try: self._file_tokens = list(tokenize.generate_tokens( - lambda: next(line_iter))) + lambda: next(line_iter) + )) except tokenize.TokenError as exc: raise exceptions.InvalidSyntax(exc.message, exception=exc) - return self._file_tokens[:] + return self._file_tokens @contextlib.contextmanager def inside_multiline(self, line_number):