Skip to content

Commit

Permalink
main: Fix unbound 'spec' variable when loading extension commands
Browse files Browse the repository at this point in the history
The 'spec' loop variable was not captured, and this would result in
the lambda function only evaluating to the last value in the loop.

The issue could occur when loading extension commands from projects,
where the name conflicts with a builtin command or an already loaded
extension command.

Discovered with flake8-bugbear, see
https://docs.astral.sh/ruff/rules/function-uses-loop-variable/

Fix function-uses-loop-variable (B023)

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
  • Loading branch information
pdgendt committed Nov 5, 2024
1 parent e05251a commit edd1cee
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/west/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,17 @@ def load_extension_specs(self):
for spec in specs:
if spec.name in self.builtins:
self.queued_io.append(
lambda cmd: cmd.wrn(
f'ignoring project {spec.project.name} '
f'extension command "{spec.name}"; '
lambda cmd, spec_const=spec: cmd.wrn(
f'ignoring project {spec_const.project.name} '
f'extension command "{spec_const.name}"; '
'this is a built in command'))
continue
if spec.name in extension_names:
self.queued_io.append(
lambda cmd: cmd.wrn(
f'ignoring project {spec.project.name} '
f'extension command "{spec.name}"; '
f'command "{spec.name}" is '
lambda cmd, spec_const=spec: cmd.wrn(
f'ignoring project {spec_const.project.name} '
f'extension command "{spec_const.name}"; '
f'command "{spec_const.name}" is '
'already defined as extension command'))
continue

Expand Down

0 comments on commit edd1cee

Please sign in to comment.