Skip to content

Enable pretty by default #19510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 26, 2025
commit afc658561be0cca1c227dea52be2bc71478bed56
13 changes: 5 additions & 8 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,16 +1019,13 @@ def add_invertible_flag(
help=argparse.SUPPRESS,
)
error_group.add_argument(
'--no-pretty',
action='store_false',
dest='pretty',
help='Disable pretty error messages (pretty is now the default).'
"--no-pretty",
action="store_false",
dest="pretty",
help="Disable pretty error messages (pretty is now the default).",
)
error_group.add_argument(
'--pretty',
action='store_true',
dest='pretty',
help=argparse.SUPPRESS
"--pretty", action="store_true", dest="pretty", help=argparse.SUPPRESS
)

incremental_group = parser.add_argument_group(
Expand Down
6 changes: 3 additions & 3 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ def parse_options(

if flags:
flag_list = flags.group(1).split()
if '--pretty' not in flag_list:
flag_list.append('--no-pretty')
if "--pretty" not in flag_list:
flag_list.append("--no-pretty")
flag_list.append("--no-site-packages") # the tests shouldn't need an installed Python
targets, options = process_options(flag_list, require_targets=False)
if targets:
Expand All @@ -357,7 +357,7 @@ def parse_options(
options.error_summary = False
options.hide_error_codes = True
options.force_union_syntax = True
flag_list = ['--no-pretty']
flag_list = ["--no-pretty"]

# Allow custom python version to override testfile_pyversion.
if all(flag.split("=")[0] != "--python-version" for flag in flag_list):
Expand Down
8 changes: 4 additions & 4 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def parse_args(line: str) -> list[str]:
"""
m = re.match("# cmd: mypy (.*)$", line)
if not m:
return ['--no-pretty'] # No args; mypy will spit out an error.
return ["--no-pretty"] # No args; mypy will spit out an error.
args = m.group(1).split()
if '--pretty' not in args:
args.append('--no-pretty')

if "--pretty" not in args:
args.append("--no-pretty")

return args

Expand Down
6 changes: 3 additions & 3 deletions mypy/test/testdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ 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"
is_pretty_test = "# NO-MODIFY" in input
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I must be missing something - why won't just checking for --pretty flag do? Yes, it will deviate from normal behavior, but be consistent with all other tests - essentially sticking to old default unless requested otherwise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @sterliakov , this is still my main approach and it is also partly working in the this test-runner to maintain the consistent behavior with all other test-runners.However, I discovered a critical technical constraint: the dmypy client itself does not accept the --pretty or --no-pretty flags.

The formatting flags must be directly passed to the server, which only worked in these two ways for me:
- During startup: $ dmypy start -- --no-pretty
- During one-shot run: $ dmypy run -- --no-pretty

Because the testcases contains a mix of commands where the flag will and won't work, I had to make #NO-MODIFY as the magic comment to recognize where to not modify the command.

For demonstration:

[case testDaemonRecheck]
$ dmypy start -- --follow-imports=error --no-error-summary
Daemon started
$ dmypy check foo.py bar.py
$ dmypy recheck
$ dmypy recheck --update foo.py --remove bar.py sir_not_appearing_in_this_film.py
foo.py:1: error: Import of "bar" ignored  [misc]
foo.py:1: note: (Using --follow-imports=error, module not passed on command line)
== Return code: 1
$ dmypy recheck --update bar.py
$ dmypy recheck --update sir_not_appearing_in_this_film.py
$ dmypy recheck --update --remove
$ dmypy stop
Daemon stopped
[file foo.py]

In this case, my first approach was to insert the --pretty flag in all of them. But dmypy recheck threw an unrecognized argument error. So I realized I cannot insert any flag in the commands following dmypy start...
Therefore, I preferred to adding --pretty flag during startup. But then the test-runner logic detecting so such --pretty flag in the other commands automatically injects the --no-pretty flag which also throws an unrecognized argument error. This led to the realization, that I also need to mark these commands someway, that the test-runner doesn't inject --no-pretty in them. The best I could think of was a magic comment #NO-MODIFY which I can use to detect these lines where the test-runner shouldn't be interfering.

I understand that this is a very bare-bones workaround, and I am open to any suggestions to make it cleaner.

modified_input = input.replace('# NO-MODIFY', '').strip()
cond1 = '--pretty' not in modified_input
modified_input = input.replace("# NO-MODIFY", "").strip()
cond1 = "--pretty" not in modified_input
cond2 = modified_input.startswith(("dmypy run", "dmypy check"))
cond3 = not is_pretty_test
if cond1 and cond2 and cond3:
parts = modified_input.split(' ', 2)
parts = modified_input.split(" ", 2)
command, subcommand = parts[0], parts[1]
args = parts[2] if len(parts) > 2 else ""
input = f"{command} {subcommand} {args} --no-pretty".strip()
Expand Down
4 changes: 2 additions & 2 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def parse_pkgs(comment: str) -> tuple[list[str], list[str]]:
def parse_mypy_args(line: str) -> list[str]:
m = re.match("# flags: (.*)$", line)
if not m:
return ['--no-pretty'] # No args; mypy will spit out an error.
return ["--no-pretty"] # No args; mypy will spit out an error.
args = m.group(1).split()
args.append('--no-pretty')
args.append("--no-pretty")

return args
6 changes: 3 additions & 3 deletions mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
sys.version_info.minor,
):
return
if '--pretty' in additional_flags:
mypy_cmdline.remove('--no-pretty')
if "--pretty" in additional_flags:
mypy_cmdline.remove("--no-pretty")

mypy_cmdline.extend(additional_flags)

# Write the program to a file.
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/daemon.test
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def bar() -> None:
[case testDaemonInspectCheck]
$ dmypy start # NO-MODIFY
Daemon started
$ dmypy check foo.py # NO-MODIFY
$ dmypy check foo.py # NO-MODIFY
Success: no issues found in 1 source file
$ dmypy check foo.py --export-types # NO-MODIFY
Success: no issues found in 1 source file
Expand Down Expand Up @@ -489,7 +489,7 @@ def unreachable(x: int) -> None:
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary --no-pretty
Daemon started
$ dmypy check foo.py --export-types # NO-MODIFY
$ dmypy inspect foo.py:1:a # NO-MODIFY
$ dmypy inspect foo.py:1:a # NO-MODIFY
invalid literal for int() with base 10: 'a'
== Return code: 2
$ dmypy inspect foo.pyc:1:2 # NO-MODIFY
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy