Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def __init__(self, data_dir: str,
version_id: str) -> None:
self.start_time = time.time()
self.data_dir = data_dir
self.errors = Errors(options.hide_error_context, options.show_column_numbers)
self.errors = Errors(options.show_error_context, options.show_column_numbers)
self.errors.set_ignore_prefix(ignore_prefix)
self.lib_path = tuple(lib_path)
self.source_set = source_set
Expand Down
14 changes: 7 additions & 7 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ class Errors:
# Collection of reported only_once messages.
only_once_messages = None # type: Set[str]

# Set to False to show "In function "foo":" messages.
hide_error_context = True # type: bool
# Set to True to show "In function "foo":" messages.
show_error_context = False # type: bool

# Set to True to show column numbers in error messages
show_column_numbers = False # type: bool

def __init__(self, hide_error_context: bool = True,
def __init__(self, show_error_context: bool = False,
show_column_numbers: bool = False) -> None:
self.error_info = []
self.import_ctx = []
Expand All @@ -116,11 +116,11 @@ def __init__(self, hide_error_context: bool = True,
self.used_ignored_lines = defaultdict(set)
self.ignored_files = set()
self.only_once_messages = set()
self.hide_error_context = hide_error_context
self.show_error_context = show_error_context
self.show_column_numbers = show_column_numbers

def copy(self) -> 'Errors':
new = Errors(self.hide_error_context, self.show_column_numbers)
new = Errors(self.show_error_context, self.show_column_numbers)
new.file = self.file
new.import_ctx = self.import_ctx[:]
new.type_name = self.type_name[:]
Expand Down Expand Up @@ -306,7 +306,7 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[Tuple[str, int, int,

for e in errors:
# Report module import context, if different from previous message.
if self.hide_error_context:
if not self.show_error_context:
pass
elif e.import_ctx != prev_import_context:
last = len(e.import_ctx) - 1
Expand All @@ -329,7 +329,7 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[Tuple[str, int, int,
file = self.simplify_path(e.file)

# Report context within a source file.
if self.hide_error_context:
if not self.show_error_context:
pass
elif (e.function_or_member != prev_function_or_member or
e.type != prev_type):
Expand Down
4 changes: 2 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def add_invertible_flag(flag: str,
" from non-Any typed functions")
add_invertible_flag('--warn-unused-ignores', default=False, strict_flag=True,
help="warn about unneeded '# type: ignore' comments")
add_invertible_flag('--show-error-context', default=True,
dest='hide_error_context',
add_invertible_flag('--show-error-context', default=False,
dest='show_error_context',
help='Precede errors with "note:" messages explaining context')
add_invertible_flag('--no-fast-parser', default=True, dest='fast_parser',
help="disable the fast parser (not recommended)")
Expand Down
4 changes: 2 additions & 2 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def __init__(self) -> None:
# Apply strict None checking
self.strict_optional = False

# Hide "note: In function "foo":" messages.
self.hide_error_context = True
# Show "note: In function "foo":" messages.
self.show_error_context = False

# Files in which to allow strict-Optional related errors
# TODO: Kill this in favor of show_none_errors
Expand Down
15 changes: 12 additions & 3 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ def f():
except ZeroDivisionError, err:
print err

[case testErrorContextConfig]
# cmd: mypy main.py
[file mypy.ini]
[[mypy]
show_error_context=True
[file main.py]
def f() -> None:
0 + ""
[out]
main.py: note: In function "f":
main.py:2: error: Unsupported operand types for + ("int" and "str")

[case testAltConfigFile]
# cmd: mypy --config-file config.ini main.py
[file config.ini]
Expand All @@ -131,7 +143,6 @@ def f():
# cmd: mypy x.py y.py z.py
[file mypy.ini]
[[mypy]
hide_error_context = True
disallow_untyped_defs = True
[[mypy-y*]
disallow_untyped_defs = False
Expand Down Expand Up @@ -161,7 +172,6 @@ x.py:1: error: Function is missing a type annotation
# cmd: mypy xx.py xy.py yx.py yy.py
[file mypy.ini]
[[mypy]
hide_error_context = True
[[mypy-*x*]
disallow_untyped_defs = True
[[mypy-*y*]
Expand Down Expand Up @@ -190,7 +200,6 @@ xx.py:1: error: Function is missing a type annotation
# cmd: mypy x.py y.py z.py
[file mypy.ini]
[[mypy]
hide_error_context = True
[[mypy-x*,z*]
disallow_untyped_defs = True
[file x.py]
Expand Down