Browse Source

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 <jholdsworth@nvidia.com>
pull/90355/head
Joel Holdsworth 2 months ago committed by Benjamin Cabé
parent
commit
6ede0d5bc1
  1. 1
      .ruff-excludes.toml
  2. 2
      scripts/build/gen_relocate_app.py

1
.ruff-excludes.toml

@ -234,7 +234,6 @@ @@ -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

2
scripts/build/gen_relocate_app.py

@ -333,7 +333,7 @@ def print_linker_sections(list_sections: 'list[OutputSection]'): @@ -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(

Loading…
Cancel
Save