Skip to content

Commit cc0e97b

Browse files
committed
Fix add_invertible_flag regression and ruff PIE810 violation
Restore the original add_invertible_flag logic where the argparse action depends on the default value. The previous commit incorrectly simplified this to always use store_true/store_false, which broke all 7 flags with default=True (--no-namespace-packages, --no-warn-no-return, --no-implicit-reexport, --no-color-output, --no-error-summary, etc). The --pretty default is now controlled solely through Options.pretty=True in options.py, keeping default=False in add_invertible_flag so the flag semantics work correctly (--pretty -> store_true, --no-pretty -> store_false). Also fix ruff PIE810 by merging startswith calls into a tuple.
1 parent e36037e commit cc0e97b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

mypy/main.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,16 @@ def add_invertible_flag(
524524
if help is not argparse.SUPPRESS:
525525
help += f" (inverse: {inverse})"
526526

527-
arg = group.add_argument(flag, action="store_true", dest=dest, help=help)
527+
arg = group.add_argument(
528+
flag, action="store_false" if default else "store_true", dest=dest, help=help
529+
)
528530
dest = arg.dest
529-
group.add_argument(inverse, action="store_false", dest=dest, help=argparse.SUPPRESS)
531+
group.add_argument(
532+
inverse,
533+
action="store_true" if default else "store_false",
534+
dest=dest,
535+
help=argparse.SUPPRESS,
536+
)
530537
if strict_flag:
531538
assert dest is not None
532539
strict_flag_names.append(flag)
@@ -1000,7 +1007,7 @@ def add_invertible_flag(
10001007
)
10011008
add_invertible_flag(
10021009
"--pretty",
1003-
default=True,
1010+
default=False,
10041011
help="Use visually nicer output in error messages:"
10051012
" Use soft word wrap, show source code snippets,"
10061013
" and show error location markers",

mypy/test/testdaemon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def run_cmd(input: str) -> tuple[int, str]:
8686
elif input.startswith("mypy ") and " -- " in input:
8787
# For mypy commands, options come before --, so insert before --
8888
input = input.replace(" -- ", " --no-pretty -- ", 1)
89-
elif input.startswith("dmypy run ") or input.startswith("dmypy start"):
89+
elif input.startswith(("dmypy run ", "dmypy start")):
9090
# dmypy commands without -- need the separator added
9191
input += " -- --no-pretty"
9292
elif input.startswith("mypy "):

0 commit comments

Comments
 (0)