Skip to content

Commit 1438f24

Browse files
authored
Enable colored output for argparse help in Python 3.14 (#621)
1 parent 66884f9 commit 1438f24

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

python_typing_update/__main__.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import asyncio
88
import logging
99
import sys
10+
from typing import Any
1011

1112
from .main import async_run
1213

@@ -15,19 +16,32 @@
1516

1617
class CustomHelpFormatter(argparse.HelpFormatter):
1718
def __init__(
18-
self, prog: str, indent_increment: int = 2,
19-
max_help_position: int = 24, width: int | None = None,
19+
self,
20+
prog: str,
21+
indent_increment: int = 2,
22+
max_help_position: int = 24,
23+
width: int | None = None,
24+
**kwargs: Any,
2025
) -> None:
2126
max_help_position = 40
2227
super().__init__(
23-
prog, indent_increment=indent_increment,
24-
max_help_position=max_help_position, width=width)
28+
prog,
29+
indent_increment=indent_increment,
30+
max_help_position=max_help_position,
31+
width=width,
32+
**kwargs,
33+
)
2534

2635

2736
async def async_main(argv: list[str] | None = None) -> int:
37+
parser_kwargs: dict[str, Any] = {}
38+
if sys.version_info >= (3, 14):
39+
parser_kwargs["color"] = True
40+
2841
parser = argparse.ArgumentParser(
2942
description="Tool to update Python typing syntax.",
3043
formatter_class=CustomHelpFormatter,
44+
**parser_kwargs,
3145
)
3246
formatter_options = parser.add_argument_group("select optional formatter")
3347
mode_options = parser.add_argument_group("select different mode")

0 commit comments

Comments
 (0)