Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ in error messages.

Use visually nicer output in error messages: use soft word wrap,
show source code snippets, and show error location markers.
This is enabled by default. Use ``--no-pretty`` to disable.

.. option:: --no-color-output

Expand Down
13 changes: 3 additions & 10 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,9 @@ def add_invertible_flag(
if help is not argparse.SUPPRESS:
help += f" (inverse: {inverse})"

arg = group.add_argument(
flag, action="store_false" if default else "store_true", dest=dest, help=help
)
arg = group.add_argument(flag, action="store_true", dest=dest, help=help)
dest = arg.dest
group.add_argument(
inverse,
action="store_true" if default else "store_false",
dest=dest,
help=argparse.SUPPRESS,
)
group.add_argument(inverse, action="store_false", dest=dest, help=argparse.SUPPRESS)
if strict_flag:
assert dest is not None
strict_flag_names.append(flag)
Expand Down Expand Up @@ -1007,7 +1000,7 @@ def add_invertible_flag(
)
add_invertible_flag(
"--pretty",
default=False,
default=True,
help="Use visually nicer output in error messages:"
" Use soft word wrap, show source code snippets,"
" and show error location markers",
Expand Down
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def __init__(self) -> None:
self.hide_error_codes = False
self.show_error_code_links = False
# Use soft word wrap and show trimmed source snippets with error location markers.
self.pretty = False
self.pretty = True
self.dump_graph = False
self.dump_deps = False
self.logical_deps = False
Expand Down
1 change: 1 addition & 0 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,7 @@ def test_stubs(args: _Arguments, use_builtins_fixtures: bool = False) -> int:

options = Options()
options.incremental = False
options.pretty = False
options.custom_typeshed_dir = args.custom_typeshed_dir
if options.custom_typeshed_dir:
options.abs_custom_typeshed_dir = os.path.abspath(options.custom_typeshed_dir)
Expand Down
3 changes: 3 additions & 0 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,14 @@ def parse_options(
raise RuntimeError("Specifying targets via the flags pragma is not supported.")
if "--show-error-codes" not in flag_list:
options.hide_error_codes = True
if "--pretty" not in flag_list:
options.pretty = False
else:
flag_list = []
options = Options()
options.error_summary = False
options.hide_error_codes = True
options.pretty = False

# Allow custom python version to override testfile_pyversion.
if all(flag.split("=")[0] != "--python-version" for flag in flag_list):
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
args.append("--hide-error-codes")
if "--disallow-empty-bodies" not in args:
args.append("--allow-empty-bodies")
if "--pretty" not in args:
args.append("--no-pretty")
# Type check the program.
fixed = [python3_path, "-m", "mypy"]
env = os.environ.copy()
Expand Down
12 changes: 12 additions & 0 deletions mypy/test/testdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def parse_script(input: list[str]) -> list[list[str]]:
def run_cmd(input: str) -> tuple[int, str]:
if input[1:].startswith("mypy run --") and "--show-error-codes" not in input:
input += " --hide-error-codes"
if "--pretty" not in input:
if input.startswith("dmypy ") and " -- " in input:
# For dmypy commands, mypy flags come after --, so append at end
input += " --no-pretty"
elif input.startswith("mypy ") and " -- " in input:
# For mypy commands, options come before --, so insert before --
input = input.replace(" -- ", " --no-pretty -- ", 1)
elif input.startswith("dmypy run ") or input.startswith("dmypy start"):
# dmypy commands without -- need the separator added
input += " -- --no-pretty"
elif input.startswith("mypy "):
input += " --no-pretty"
if input.startswith("dmypy "):
input = sys.executable + " -m mypy." + input
if input.startswith("mypy "):
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testerrorstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_error_stream(testcase: DataDrivenTestCase) -> None:
options = Options()
options.show_traceback = True
options.hide_error_codes = True
options.pretty = False

logged_messages: list[str] = []

Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_pep561(testcase: DataDrivenTestCase) -> None:
f.write(f"{s}\n")
cmd_line.append(program)

cmd_line.extend(["--no-error-summary", "--hide-error-codes"])
cmd_line.extend(["--no-error-summary", "--hide-error-codes", "--no-pretty"])
if python_executable != sys.executable:
cmd_line.append(f"--python-executable={python_executable}")

Expand Down
1 change: 1 addition & 0 deletions mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
"--no-error-summary",
"--hide-error-codes",
"--allow-empty-bodies",
"--no-pretty",
"--test-env", # Speeds up some checks
]
interpreter = python3_path
Expand Down
2 changes: 1 addition & 1 deletion mypyc/test/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
try:
# Compile program
cmd = subprocess.run(
[sys.executable, "-m", "mypyc", *args],
[sys.executable, "-m", "mypyc", "--no-pretty", *args],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd="tmp",
Expand Down
Loading