From 6ede0d5bc1a65408131f35047b85f4aeffc4401c Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Wed, 21 May 2025 10:31:27 -0700 Subject: [PATCH] code_relocation: fix ruff SUM401 warning The ruff python linter produces a SIM401 warning when a dictionary is accessed using if-statements to check for key presence. In this case, the dict.get() method could be used instead. For example: value = foo["bar"] if "bar" in foo else 0 ...can be replaced with: value = foo.get("bar", 0) This patch corrects the single instance of this issue in the script. Signed-off-by: Joel Holdsworth --- .ruff-excludes.toml | 1 - scripts/build/gen_relocate_app.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.ruff-excludes.toml b/.ruff-excludes.toml index 35fb46d7ac0..4abc09f3d7b 100644 --- a/.ruff-excludes.toml +++ b/.ruff-excludes.toml @@ -234,7 +234,6 @@ ] "./scripts/build/gen_relocate_app.py" = [ "E101", # https://docs.astral.sh/ruff/rules/mixed-spaces-and-tabs - "SIM401", # https://docs.astral.sh/ruff/rules/if-else-block-instead-of-dict-get "UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation "UP035", # https://docs.astral.sh/ruff/rules/deprecated-import "UP037", # https://docs.astral.sh/ruff/rules/quoted-annotation diff --git a/scripts/build/gen_relocate_app.py b/scripts/build/gen_relocate_app.py index a78992e95c4..beccca57dff 100755 --- a/scripts/build/gen_relocate_app.py +++ b/scripts/build/gen_relocate_app.py @@ -333,7 +333,7 @@ def print_linker_sections(list_sections: 'list[OutputSection]'): def add_phdr(memory_type, phdrs): - return f'{memory_type} {phdrs[memory_type] if memory_type in phdrs else ""}' + return f'{memory_type} {phdrs.get(memory_type, "")}' def string_create_helper(