mypy now passes

This commit is contained in:
Anthony Sottile 2019-05-19 17:01:14 -07:00
parent b6ba6d4d03
commit fb7e9338cd
32 changed files with 255 additions and 212 deletions

View file

@ -1,6 +1,11 @@
"""Default formatting class for Flake8."""
from typing import Optional, Set
from flake8.formatting import base
if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2
from flake8.style_guide import Violation
class SimpleFormatter(base.BaseFormatter):
"""Simple abstraction for Default and Pylint formatter commonality.
@ -18,9 +23,9 @@ class SimpleFormatter(base.BaseFormatter):
"""
error_format = None
error_format = None # type: str
def format(self, error):
def format(self, error): # type: (Violation) -> Optional[str]
"""Format and write error out.
If an output filename is specified, write formatted errors to that
@ -44,7 +49,7 @@ class Default(SimpleFormatter):
error_format = "%(path)s:%(row)d:%(col)d: %(code)s %(text)s"
def after_init(self):
def after_init(self): # type: () -> None
"""Check for a custom format string."""
if self.options.format.lower() != "default":
self.error_format = self.options.format
@ -61,28 +66,27 @@ class FilenameOnly(SimpleFormatter):
error_format = "%(path)s"
def after_init(self):
def after_init(self): # type: () -> None
"""Initialize our set of filenames."""
self.filenames_already_printed = set()
self.filenames_already_printed = set() # type: Set[str]
def show_source(self, error):
def show_source(self, error): # type: (Violation) -> Optional[str]
"""Do not include the source code."""
pass
def format(self, error):
def format(self, error): # type: (Violation) -> Optional[str]
"""Ensure we only print each error once."""
if error.filename not in self.filenames_already_printed:
self.filenames_already_printed.add(error.filename)
return super(FilenameOnly, self).format(error)
else:
return None
class Nothing(base.BaseFormatter):
"""Print absolutely nothing."""
def format(self, error):
def format(self, error): # type: (Violation) -> Optional[str]
"""Do nothing."""
pass
def show_source(self, error):
def show_source(self, error): # type: (Violation) -> Optional[str]
"""Do not print the source."""
pass