def _pep8_annotations(text, ignore=None, max_line_length=None):
import pep8
class _Pep8AnnotationReport(pep8.BaseReport):
def __init__(self, options):
super().__init__(options)
self.annotations = []
def error(self, line_number, offset, text, check):
# If super doesn't return code, this one is ignored
if not super().error(line_number, offset, text, check):
return
annotation = _AnalyzerAnnotation(self.line_offset + line_number, text, _Source.pep8, Style.warning)
self.annotations.append(annotation)
# pep8 requires you to include \n at the end of lines
lines = text.splitlines(True)
style_guide = pep8.StyleGuide(reporter=_Pep8AnnotationReport, )
options = style_guide.options
if ignore:
options.ignore = tuple(ignore)
else:
options.ignore = tuple()
if max_line_length:
options.max_line_length = max_line_length
checker = pep8.Checker(None, lines, options, None)
checker.check_all()
return checker.report.annotations
#
# pyflakes
#
评论列表
文章目录