diff --git a/mypy/build.py b/mypy/build.py index 9e7af6f80931..cb346efda4b8 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -330,7 +330,7 @@ def __init__(self, data_dir: str, options: Options) -> None: self.start_time = time.time() self.data_dir = data_dir - self.errors = Errors() + self.errors = Errors(options.suppress_error_context) self.errors.set_ignore_prefix(ignore_prefix) self.lib_path = tuple(lib_path) self.source_set = source_set diff --git a/mypy/errors.py b/mypy/errors.py index 25f7ed0c2057..c594a4b4e237 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -89,7 +89,10 @@ class Errors: # Collection of reported only_once messages. only_once_messages = None # type: Set[str] - def __init__(self) -> None: + # Set to True to suppress "In function "foo":" messages. + suppress_error_context = False # type: bool + + def __init__(self, suppress_error_context: bool = False) -> None: self.error_info = [] self.import_ctx = [] self.type_name = [None] @@ -97,9 +100,10 @@ def __init__(self) -> None: self.ignored_lines = OrderedDict() self.used_ignored_lines = defaultdict(set) self.only_once_messages = set() + self.suppress_error_context = suppress_error_context def copy(self) -> 'Errors': - new = Errors() + new = Errors(self.suppress_error_context) new.file = self.file new.import_ctx = self.import_ctx[:] new.type_name = self.type_name[:] @@ -287,7 +291,9 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[Tuple[str, int, file = self.simplify_path(e.file) # Report context within a source file. - if (e.function_or_member != prev_function_or_member or + if self.suppress_error_context: + pass + elif (e.function_or_member != prev_function_or_member or e.type != prev_type): if e.function_or_member is None: if e.type is None: diff --git a/mypy/main.py b/mypy/main.py index 80ae44da2122..b78fbb393dbf 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -162,6 +162,9 @@ def parse_version(v: str) -> Tuple[int, int]: help="warn about casting an expression to its inferred type") parser.add_argument('--warn-unused-ignores', action='store_true', help="warn about unneeded '# type: ignore' comments") + parser.add_argument('--suppress-error-context', action='store_true', + dest='suppress_error_context', + help="Suppress context notes before errors") parser.add_argument('--fast-parser', action='store_true', help="enable experimental fast parser") parser.add_argument('-i', '--incremental', action='store_true', diff --git a/mypy/options.py b/mypy/options.py index cf1340af3978..5f26a32663d2 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -56,6 +56,7 @@ def __init__(self) -> None: self.fast_parser = False self.incremental = False self.cache_dir = defaults.MYPY_CACHE + self.suppress_error_context = False # Suppress "note: In function "foo":" messages. def __eq__(self, other: object) -> bool: return self.__class__ == other.__class__ and self.__dict__ == other.__dict__