Skip to content

Commit 78c45c9

Browse files
committed
cli/_formatter(refactor[typing]): Define help theme protocol
why: Replace t.Any theme annotations with explicit attributes used by the formatter. what: - Add _HelpTheme protocol for heading/option color fields - Cast _theme to the protocol type when reading - Use _HelpTheme in _colorize_example_line
1 parent 8a01c0a commit 78c45c9

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/vcspull/cli/_formatter.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@
3535
}
3636

3737

38+
class _HelpTheme(t.Protocol):
39+
heading: str
40+
reset: str
41+
label: str
42+
long_option: str
43+
short_option: str
44+
prog: str
45+
action: str
46+
47+
3848
class VcspullHelpFormatter(argparse.RawDescriptionHelpFormatter):
3949
"""Render description blocks while colorizing example sections when possible."""
4050

4151
def _fill_text(self, text: str, width: int, indent: str) -> str:
42-
theme = getattr(self, "_theme", None)
52+
theme = t.cast("_HelpTheme | None", getattr(self, "_theme", None))
4353
if not text or theme is None:
4454
return super()._fill_text(text, width, indent)
4555

@@ -93,7 +103,7 @@ def _colorize_example_line(
93103
self,
94104
content: str,
95105
*,
96-
theme: t.Any,
106+
theme: _HelpTheme,
97107
expect_value: bool,
98108
) -> _ColorizedLine:
99109
parts: list[str] = []

0 commit comments

Comments
 (0)