Skip to content

Commit a3a25eb

Browse files
gvanrossumddfisher
authored andcommitted
Add --suppress-error-context flag to suppress notes about class/function (#1922)
Fixes #1821. (well enough for now)
1 parent aeea17a commit a3a25eb

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

mypy/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def __init__(self, data_dir: str,
330330
options: Options) -> None:
331331
self.start_time = time.time()
332332
self.data_dir = data_dir
333-
self.errors = Errors()
333+
self.errors = Errors(options.suppress_error_context)
334334
self.errors.set_ignore_prefix(ignore_prefix)
335335
self.lib_path = tuple(lib_path)
336336
self.source_set = source_set

mypy/errors.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,21 @@ class Errors:
8989
# Collection of reported only_once messages.
9090
only_once_messages = None # type: Set[str]
9191

92-
def __init__(self) -> None:
92+
# Set to True to suppress "In function "foo":" messages.
93+
suppress_error_context = False # type: bool
94+
95+
def __init__(self, suppress_error_context: bool = False) -> None:
9396
self.error_info = []
9497
self.import_ctx = []
9598
self.type_name = [None]
9699
self.function_or_member = [None]
97100
self.ignored_lines = OrderedDict()
98101
self.used_ignored_lines = defaultdict(set)
99102
self.only_once_messages = set()
103+
self.suppress_error_context = suppress_error_context
100104

101105
def copy(self) -> 'Errors':
102-
new = Errors()
106+
new = Errors(self.suppress_error_context)
103107
new.file = self.file
104108
new.import_ctx = self.import_ctx[:]
105109
new.type_name = self.type_name[:]
@@ -287,7 +291,9 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[Tuple[str, int,
287291
file = self.simplify_path(e.file)
288292

289293
# Report context within a source file.
290-
if (e.function_or_member != prev_function_or_member or
294+
if self.suppress_error_context:
295+
pass
296+
elif (e.function_or_member != prev_function_or_member or
291297
e.type != prev_type):
292298
if e.function_or_member is None:
293299
if e.type is None:

mypy/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ def parse_version(v: str) -> Tuple[int, int]:
162162
help="warn about casting an expression to its inferred type")
163163
parser.add_argument('--warn-unused-ignores', action='store_true',
164164
help="warn about unneeded '# type: ignore' comments")
165+
parser.add_argument('--suppress-error-context', action='store_true',
166+
dest='suppress_error_context',
167+
help="Suppress context notes before errors")
165168
parser.add_argument('--fast-parser', action='store_true',
166169
help="enable experimental fast parser")
167170
parser.add_argument('-i', '--incremental', action='store_true',

mypy/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self) -> None:
5656
self.fast_parser = False
5757
self.incremental = False
5858
self.cache_dir = defaults.MYPY_CACHE
59+
self.suppress_error_context = False # Suppress "note: In function "foo":" messages.
5960

6061
def __eq__(self, other: object) -> bool:
6162
return self.__class__ == other.__class__ and self.__dict__ == other.__dict__

0 commit comments

Comments
 (0)