Skip to content

Commit b1f9428

Browse files
erwangokartben
authored andcommitted
scripts: runners: stm32cubeprogrammer: Factorize type lambda function
Now that it is used twice, factorize lambda and comment. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent 3bddb13 commit b1f9428

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Diff for: scripts/west_commands/runners/stm32cubeprogrammer.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def capabilities(cls):
146146

147147
@classmethod
148148
def do_add_parser(cls, parser):
149+
# To accept arguments in hex format, a wrapper lambda around int() must be used.
150+
# Wrapping the lambda with functools.wraps() makes it so that 'invalid int value'
151+
# is displayed when an invalid value is provided for these arguments.
152+
multi_base=functools.wraps(int)(lambda s: int(s, base=0))
149153
parser.add_argument(
150154
"--port",
151155
type=str,
@@ -164,12 +168,9 @@ def do_add_parser(cls, parser):
164168
)
165169
parser.add_argument(
166170
"--download-address",
167-
# To accept arguments in hex format, a wrapper lambda around int() must be used.
168-
# Wrapping the lambda with functools.wraps() makes it so that 'invalid int value'
169-
# is displayed when an invalid value is provided for this argument.
170-
type=functools.wraps(int)(lambda s: int(s, base=0)),
171+
type=multi_base,
171172
required=False,
172-
help="Flashing location address. To be used only with .bin files"
173+
help="Flashing location address. If present, .bin used instead of .hex"
173174
)
174175
parser.add_argument(
175176
"--download-modifiers",
@@ -180,10 +181,7 @@ def do_add_parser(cls, parser):
180181
)
181182
parser.add_argument(
182183
"--start-address",
183-
# To accept arguments in hex format, a wrapper lambda around int() must be used.
184-
# Wrapping the lambda with functools.wraps() makes it so that 'invalid int value'
185-
# is displayed when an invalid value is provided for this argument.
186-
type=functools.wraps(int)(lambda s: int(s, base=0)),
184+
type=multi_base,
187185
required=False,
188186
help="Address where execution should begin after flashing"
189187
)

0 commit comments

Comments
 (0)