Skip to content

Commit 1430ab6

Browse files
committed
Add type annotations to custom argparse actions
Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent 9fb7541 commit 1430ab6

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

codebasin/config.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,24 @@ class _StoreSplitAction(argparse.Action):
100100
separator, then stores the resulting list.
101101
"""
102102

103-
def __init__(self, option_strings, dest, nargs=None, **kwargs):
103+
def __init__(
104+
self,
105+
option_strings: list[str],
106+
dest: str,
107+
nargs=None,
108+
**kwargs,
109+
):
104110
self.sep = kwargs.pop("sep", None)
105111
self.format = kwargs.pop("format", None)
106112
super().__init__(option_strings, dest, nargs=nargs, **kwargs)
107113

108-
def __call__(self, parser, namespace, values, option_string):
114+
def __call__(
115+
self,
116+
parser: argparse.ArgumentParser,
117+
namespace: argparse.Namespace,
118+
values: str,
119+
option_string: str,
120+
):
109121
if not isinstance(values, str):
110122
raise TypeError("store_split expects string values")
111123
split_values = values.split(self.sep)
@@ -125,12 +137,24 @@ class _ExtendMatchAction(argparse.Action):
125137
pattern, then extends the destination list using the result(s).
126138
"""
127139

128-
def __init__(self, option_strings, dest, nargs=None, **kwargs):
140+
def __init__(
141+
self,
142+
option_strings: list[str],
143+
dest: str,
144+
nargs=None,
145+
**kwargs,
146+
):
129147
self.pattern = kwargs.pop("pattern", None)
130148
self.format = kwargs.pop("format", None)
131149
super().__init__(option_strings, dest, nargs=nargs, **kwargs)
132150

133-
def __call__(self, parser, namespace, value, option_string):
151+
def __call__(
152+
self,
153+
parser: argparse.ArgumentParser,
154+
namespace: argparse.Namespace,
155+
value: str,
156+
option_string: str,
157+
):
134158
if not isinstance(value, str):
135159
raise TypeError("extend_match expects string value")
136160
matches = re.findall(self.pattern, value)

0 commit comments

Comments
 (0)