8000 Enable colored output for argparse help in Python 3.14 (#19021) · python/mypy@e7405c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7405c9

Browse files
authored
Enable colored output for argparse help in Python 3.14 (#19021)
Support for colored output was just merged in cpython. Maybe a bit early to add it here already but it doesn't hurt either. | Current | With color | | --- | --- | | <img width="1058" alt="Without color" src="https://github.com/user-attachments/assets/48edae3e-9361-4af0-aff6-7931410bcd2e" /> | <img width="944" alt="With color" src="https://github.com/user-attachments/assets/38e64082-0321-4d36-a5fe-4d59c6eddc31" /> | The color output can be disable using various environment variables. https://docs.python.org/3.14/using/cmdline.html#using-on-controlling-color
1 parent d68ea35 commit e7405c9

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

mypy/dmypy/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def __init__(self, prog: str, **kwargs: Any) -> None:
3636
parser = argparse.ArgumentParser(
3737
prog="dmypy", description="Client for mypy daemon mode", fromfile_prefix_chars="@"
3838
)
39+
if sys.version_info >= (3, 14):
40+
parser.color = True # Set as init arg in 3.14
41+
3942
parser.set_defaults(action=None)
4043
parser.add_argument(
4144
"--status-file", default=DEFAULT_STATUS_FILE, help="status file to retrieve daemon details"

mypy/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ def process_options(
491491
stdout=stdout,
492492
stderr=stderr,
493493
)
494+
if sys.version_info >= (3, 14):
495+
parser.color = True # Set as init arg in 3.14
494496

495497
strict_flag_names: list[str] = []
496498
strict_flag_assignments: list[tuple[str, bool]] = []

mypy/stubgen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,8 @@ def parse_options(args: list[str]) -> Options:
18511851
parser = argparse.ArgumentParser(
18521852
prog="stubgen", usage=HEADER, description=DESCRIPTION, fromfile_prefix_chars="@"
18531853
)
1854+
if sys.version_info >= (3, 14):
1855+
parser.color = True # Set as init arg in 3.14
18541856

18551857
parser.add_argument(
18561858
"--ignore-errors",

mypy/stubtest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,8 @@ def parse_options(args: list[str]) -> _Arguments:
20842084
parser = argparse.ArgumentParser(
20852085
description="Compares stubs to objects introspected from the runtime."
20862086
)
2087+
if sys.version_info >= (3, 14):
2088+
parser.color = True # Set as init arg in 3.14
20872089
parser.add_argument("modules", na 473E rgs="*", help="Modules to test")
20882090
parser.add_argument(
20892091
"--concise",

0 commit comments

Comments
 (0)
0