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
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
70 changes: 70 additions & 0 deletions mypy/test/testdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import annotations

import os
import re
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -76,9 +77,78 @@ def parse_script(input: list[str]) -> list[list[str]]:
return steps


def _add_no_pretty_to_dmypy(input: str) -> str:
"""Add --no-pretty to a dmypy run/start command that has no -- separator.

For dmypy run/start, mypy flags are passed as positional args after --.
When the command has no --, we need to insert -- before the positional args
and append --no-pretty. We must keep any dmypy-specific named flags
(like --export-types, --log-file FILE) before the -- separator.
"""
# Match: "dmypy run" or "dmypy start", then the rest of the args
m = re.match(r"(dmypy (?:run|start))\s*(.*)", input)
if not m:
return input
prefix = m.group(1)
rest = m.group(2)

# Known dmypy run/start flags that take no value
no_value_flags = {"--export-types", "--verbose", "-v"}
# Known dmypy run/start flags that take a value
value_flags = {"--log-file", "--timeout", "--junit-xml", "--perf-stats-file"}

parts = rest.split()
dmypy_flags: list[str] = []
positional: list[str] = []
i = 0
while i < len(parts):
if parts[i] in no_value_flags:
dmypy_flags.append(parts[i])
i += 1
elif parts[i] in value_flags:
dmypy_flags.append(parts[i])
if i + 1 < len(parts):
dmypy_flags.append(parts[i + 1])
i += 2
elif parts[i].startswith("-") and "=" in parts[i]:
# Handle --flag=value style for known flags
flag_name = parts[i].split("=")[0]
if flag_name in value_flags:
dmypy_flags.append(parts[i])
else:
positional.append(parts[i])
i += 1
else:
positional.append(parts[i])
i += 1

dmypy_part = " ".join(dmypy_flags)
positional_part = " ".join(positional)
result = prefix
if dmypy_part:
result += " " + dmypy_part
result += " -- "
if positional_part:
result += positional_part + " "
result += "--no-pretty"
return result


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 run ", "dmypy start")) and " -- " in input:
# For dmypy run/start, 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 ", "dmypy start")):
# dmypy run/start without -- need the separator added
input = _add_no_pretty_to_dmypy(input)
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