summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabian Neundorf <CommodoreFabianus@gmx.de>2016-07-21 11:55:41 +0000
committerFabian Neundorf <CommodoreFabianus@gmx.de>2016-07-22 00:28:23 +0200
commit9cf8603e9494420ebd1a48bea33b31d4979525d7 (patch)
tree5dbcb788ecec3349d9a5579a699c238fc747e196 /src
parentc3ee4829ed8d8286a167949ed6ca09a4db571318 (diff)
downloadflake8-9cf8603e9494420ebd1a48bea33b31d4979525d7.tar.gz
Add support for tokens of a complete file
The `tokens` property of the `FileProcessor` class only contains tokens of the current line but not all tokens. So if a plugin which is only executed once per file, that property is useless. To make the tokens also available to plugins it is now be able to supply all the tokens of a file. It also updates the documentation to separate which parameters are static and which are changed on each line. Using the latter parameters on plugins which are only run once per file isn't very sensible.
Diffstat (limited to 'src')
-rw-r--r--src/flake8/processor.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/flake8/processor.py b/src/flake8/processor.py
index dee0b15..79844af 100644
--- a/src/flake8/processor.py
+++ b/src/flake8/processor.py
@@ -43,6 +43,7 @@ class FileProcessor(object):
- :attr:`previous_indent_level`
- :attr:`previous_logical`
- :attr:`tokens`
+ - :attr:`file_tokens`
- :attr:`total_lines`
- :attr:`verbose`
"""
@@ -101,6 +102,19 @@ class FileProcessor(object):
self.statistics = {
'logical lines': 0,
}
+ self._file_tokens = None
+
+ @property
+ def file_tokens(self):
+ if self._file_tokens is None:
+ line_iter = iter(self.lines)
+ try:
+ self._file_tokens = list(tokenize.generate_tokens(
+ lambda: next(line_iter)))
+ except tokenize.TokenError as exc:
+ raise exceptions.InvalidSyntax(exc.message, exception=exc)
+
+ return self._file_tokens[:]
@contextlib.contextmanager
def inside_multiline(self, line_number):