mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 06:14:17 +00:00
Add type annotations
This commit is contained in:
parent
51d15295df
commit
1cd5fea730
2 changed files with 15 additions and 2 deletions
|
|
@ -62,6 +62,7 @@ class Manager(object):
|
||||||
self.process_queue = multiprocessing.Queue()
|
self.process_queue = multiprocessing.Queue()
|
||||||
|
|
||||||
def _job_count(self):
|
def _job_count(self):
|
||||||
|
# type: () -> Union[int, NoneType]
|
||||||
# First we walk through all of our error cases:
|
# First we walk through all of our error cases:
|
||||||
# - multiprocessing library is not present
|
# - multiprocessing library is not present
|
||||||
# - we're running on windows in which case we know we have significant
|
# - we're running on windows in which case we know we have significant
|
||||||
|
|
@ -181,6 +182,7 @@ class FileChecker(object):
|
||||||
self.lines = []
|
self.lines = []
|
||||||
|
|
||||||
def read_lines(self):
|
def read_lines(self):
|
||||||
|
# type: () -> List[str]
|
||||||
"""Read the lines for this file checker."""
|
"""Read the lines for this file checker."""
|
||||||
if self.filename is None or self.filename == '-':
|
if self.filename is None or self.filename == '-':
|
||||||
self.filename = 'stdin'
|
self.filename = 'stdin'
|
||||||
|
|
@ -188,10 +190,12 @@ class FileChecker(object):
|
||||||
return self.read_lines_from_filename()
|
return self.read_lines_from_filename()
|
||||||
|
|
||||||
def _readlines_py2(self):
|
def _readlines_py2(self):
|
||||||
|
# type: () -> List[str]
|
||||||
with open(self.filename, 'rU') as fd:
|
with open(self.filename, 'rU') as fd:
|
||||||
return fd.readlines()
|
return fd.readlines()
|
||||||
|
|
||||||
def _readlines_py3(self):
|
def _readlines_py3(self):
|
||||||
|
# type: () -> List[str]
|
||||||
try:
|
try:
|
||||||
with open(self.filename, 'rb') as fd:
|
with open(self.filename, 'rb') as fd:
|
||||||
(coding, lines) = tokenize.detect_encoding(fd.readline)
|
(coding, lines) = tokenize.detect_encoding(fd.readline)
|
||||||
|
|
@ -205,6 +209,7 @@ class FileChecker(object):
|
||||||
return fd.readlines()
|
return fd.readlines()
|
||||||
|
|
||||||
def read_lines_from_filename(self):
|
def read_lines_from_filename(self):
|
||||||
|
# type: () -> List[str]
|
||||||
"""Read the lines for a file."""
|
"""Read the lines for a file."""
|
||||||
if (2, 6) <= sys.version_info < (3, 0):
|
if (2, 6) <= sys.version_info < (3, 0):
|
||||||
readlines = self._readlines_py2
|
readlines = self._readlines_py2
|
||||||
|
|
@ -222,19 +227,27 @@ class FileChecker(object):
|
||||||
# going forward.
|
# going forward.
|
||||||
(exc_type, exception) = sys.exc_info()[:2]
|
(exc_type, exception) = sys.exc_info()[:2]
|
||||||
message = '{0}: {1}'.format(exc_type.__name__, exception)
|
message = '{0}: {1}'.format(exc_type.__name__, exception)
|
||||||
self.results.append('E902', self.filename, 0, 0, message)
|
self.report('E902', 0, 0, message)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def read_lines_from_stdin(self):
|
def read_lines_from_stdin(self):
|
||||||
|
# type: () -> List[str]
|
||||||
"""Read the lines from standard in."""
|
"""Read the lines from standard in."""
|
||||||
return utils.stdin_get_value().splitlines(True)
|
return utils.stdin_get_value().splitlines(True)
|
||||||
|
|
||||||
|
def report(self, error_code, line_number, column, text):
|
||||||
|
# type: (str, int, int, str) -> NoneType
|
||||||
|
"""Report an error by storing it in the results list."""
|
||||||
|
error = (error_code, self.filename, line_number, column, text)
|
||||||
|
self.results.append(error)
|
||||||
|
|
||||||
def run_checks(self):
|
def run_checks(self):
|
||||||
"""Run checks against the file."""
|
"""Run checks against the file."""
|
||||||
self.lines = self.read_lines()
|
self.lines = self.read_lines()
|
||||||
self.strip_utf_bom()
|
self.strip_utf_bom()
|
||||||
|
|
||||||
def strip_utf_bom(self):
|
def strip_utf_bom(self):
|
||||||
|
# type: () -> NoneType
|
||||||
"""Strip the UTF bom from the lines of the file."""
|
"""Strip the UTF bom from the lines of the file."""
|
||||||
if not self.lines:
|
if not self.lines:
|
||||||
# If we have nothing to analyze quit early
|
# If we have nothing to analyze quit early
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ def _default_predicate(*args):
|
||||||
|
|
||||||
|
|
||||||
def filenames_from(arg, predicate=None):
|
def filenames_from(arg, predicate=None):
|
||||||
# type: (str) -> Generator
|
# type: (str, callable) -> Generator
|
||||||
"""Generate filenames from an argument.
|
"""Generate filenames from an argument.
|
||||||
|
|
||||||
:param str arg:
|
:param str arg:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue