mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-03 19:56:54 +00:00
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.
This commit is contained in:
parent
1cfc12f366
commit
8dfe38e9e6
1 changed files with 9 additions and 2 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue