scripts: Remove unused variables in all Python scripts
Discovered with pylint3.
Use the placeholder name '_' for unproblematic unused variables. It's
what I'm used to, and pylint knows not to flag it.
Python tip:
for i in range(n):
some_list.append(0)
can be replaced with
some_list += n*[0]
Similarly, 3*'\t' gives '\t\t\t'.
(Relevant here because pylint flagged the loop index as unused.)
To do integer division in Python 3, use // instead of /.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
diff --git a/arch/common/gen_isr_tables.py b/arch/common/gen_isr_tables.py
index 012e80c..ad02d72 100755
--- a/arch/common/gen_isr_tables.py
+++ b/arch/common/gen_isr_tables.py
@@ -223,7 +223,6 @@
intlist = read_intlist(args.intlist)
nvec = intlist["num_vectors"]
offset = intlist["offset"]
- prefix = endian_prefix()
spurious_handler = "&z_irq_spurious"
sw_irq_handler = "ISR_WRAPPER"
diff --git a/arch/x86/gen_mmu_x86.py b/arch/x86/gen_mmu_x86.py
index 0ea72fa..f30579b 100755
--- a/arch/x86/gen_mmu_x86.py
+++ b/arch/x86/gen_mmu_x86.py
@@ -394,7 +394,7 @@
self.output_offset += struct.calcsize(page_entry_format)
def page_table_create_binary_file(self):
- for pdpte, pde_info in sorted(self.list_of_pdpte.items()):
+ for _, pde_info in sorted(self.list_of_pdpte.items()):
for pde, pte_info in sorted(pde_info.pd_entries.items()):
pe_info = pte_info.page_entries_info[0]
start_addr = pe_info.start_addr & ~0x1FFFFF
diff --git a/arch/xtensa/core/xtensa_intgen.py b/arch/xtensa/core/xtensa_intgen.py
index c733230..6985961 100755
--- a/arch/xtensa/core/xtensa_intgen.py
+++ b/arch/xtensa/core/xtensa_intgen.py
@@ -29,8 +29,7 @@
return
if s.find("}") >= 0:
cindent -= 1
- for xx in range(cindent):
- s = "\t" + s
+ s = cindent*"\t" + s
print(s)
if s.find("{") >= 0:
cindent += 1
diff --git a/boards/xtensa/intel_s1000_crb/support/create_board_img.py b/boards/xtensa/intel_s1000_crb/support/create_board_img.py
index 4271dc8..5c6bdec 100644
--- a/boards/xtensa/intel_s1000_crb/support/create_board_img.py
+++ b/boards/xtensa/intel_s1000_crb/support/create_board_img.py
@@ -188,9 +188,8 @@
ipc_load_fw(SRAM_SIZE, FLASH_PART_TABLE_OFFSET)
# pad zeros until FLASH_PART_TABLE_OFFSET
- num_zero_pad = (FLASH_PART_TABLE_OFFSET / 4) - len(flash_content)
- for x in range(int(num_zero_pad)):
- flash_content.append(0)
+ num_zero_pad = FLASH_PART_TABLE_OFFSET // 4 - len(flash_content)
+ flash_content += num_zero_pad * [0]
# read contents of firmware input file and change the endianness
with open(args.in_file, "rb") as in_fp:
@@ -203,8 +202,7 @@
write_buf.append(read_buf[itr*4 + 0])
# pad zeros until the sector boundary
- for x in range(zeropad_size):
- write_buf.append(0)
+ write_buf += zeropad_size*[0]
# Generate the file which should be downloaded to Flash
with open(args.out_file, "wb") as out_fp:
diff --git a/doc/extensions/local_util.py b/doc/extensions/local_util.py
index 0614f3f..12d03a7 100644
--- a/doc/extensions/local_util.py
+++ b/doc/extensions/local_util.py
@@ -57,7 +57,7 @@
return
src_path_len = len(src_path)
- for root, dirs, files in os.walk(src_path):
+ for root, _, files in os.walk(src_path):
for src_file_name in files:
src_file_path = os.path.join(root, src_file_name)
dst_file_path = os.path.join(dst_path + root[src_path_len:], src_file_name)
diff --git a/doc/extensions/zephyr/application.py b/doc/extensions/zephyr/application.py
index 9d3e242..3ff8a36 100644
--- a/doc/extensions/zephyr/application.py
+++ b/doc/extensions/zephyr/application.py
@@ -164,7 +164,6 @@
if v != 'all']
# Build the command content as a list, then convert to string.
content = []
- lit = []
cd_to = zephyr_app or app
tool_comment = None
if len(tools) > 1:
@@ -336,7 +335,6 @@
zephyr_app = kwargs['zephyr_app']
host_os = kwargs['host_os']
build_dir = kwargs['build_dir']
- source_dir = kwargs['source_dir']
skip_config = kwargs['skip_config']
compact = kwargs['compact']
generator = kwargs['generator']
diff --git a/ext/hal/nxp/mcux/scripts/import_mcux_sdk.py b/ext/hal/nxp/mcux/scripts/import_mcux_sdk.py
index 5029991..30ce2c1 100755
--- a/ext/hal/nxp/mcux/scripts/import_mcux_sdk.py
+++ b/ext/hal/nxp/mcux/scripts/import_mcux_sdk.py
@@ -65,7 +65,7 @@
device_src = os.path.join(directory, 'devices', device)
device_pattern = "|".join([device, 'fsl_device_registers'])
- [device_headers, ignore] = get_files(device_src, device_pattern)
+ device_headers, _ = get_files(device_src, device_pattern)
drivers_src = os.path.join(directory, 'devices', device, 'drivers')
drivers_pattern = "fsl_clock|fsl_iomuxc"
@@ -73,7 +73,7 @@
xip_boot_src = os.path.join(directory, 'devices', device, 'xip')
xip_boot_pattern = ".*"
- [xip_boot, ignore] = get_files(xip_boot_src, xip_boot_pattern)
+ xip_boot, _ = get_files(xip_boot_src, xip_boot_pattern)
print('Importing {} device headers to {}'.format(device, device_dst))
copy_files(device_headers, device_dst)
@@ -93,7 +93,7 @@
xip_config_src = os.path.join(board_src, 'xip')
xip_config_pattern = ".*"
- [xip_config, ignore] = get_files(xip_config_src, xip_config_pattern)
+ xip_config, _ = get_files(xip_config_src, xip_config_pattern)
print('Importing {} xip config to {}'.format(board, board_dst))
copy_files(xip_config, board_dst)
diff --git a/scripts/elf_helper.py b/scripts/elf_helper.py
index ad08aab..263c80f 100644
--- a/scripts/elf_helper.py
+++ b/scripts/elf_helper.py
@@ -386,7 +386,7 @@
# Step 1: collect all type information.
for CU in di.iter_CUs():
- for idx, die in enumerate(CU.iter_DIEs()):
+ for die in CU.iter_DIEs():
# Unions are disregarded, kernel objects should never be union
# members since the memory is not dedicated to that object and
# could be something else
diff --git a/scripts/filter-known-issues.py b/scripts/filter-known-issues.py
index 3d20106..4686396 100755
--- a/scripts/filter-known-issues.py
+++ b/scripts/filter-known-issues.py
@@ -89,7 +89,7 @@
"""
file_regex = re.compile(".*\.conf$")
try:
- for dirpath, dirnames, filenames in os.walk(path):
+ for dirpath, _, filenames in os.walk(path):
for _filename in sorted(filenames):
filename = os.path.join(dirpath, _filename)
if not file_regex.search(_filename):
diff --git a/scripts/gen_app_partitions.py b/scripts/gen_app_partitions.py
index 2ce38e1..99a10c3 100644
--- a/scripts/gen_app_partitions.py
+++ b/scripts/gen_app_partitions.py
@@ -128,7 +128,7 @@
def parse_obj_files(partitions):
# Iterate over all object files to find partitions
- for dirpath, dirs, files in os.walk(args.directory):
+ for dirpath, _, files in os.walk(args.directory):
for filename in files:
if re.match(".*\.obj$",filename):
fullname = os.path.join(dirpath, filename)
@@ -143,7 +143,7 @@
if isinstance(s, SymbolTableSection)]
for section in symbol_tbls:
- for nsym, symbol in enumerate(section.iter_symbols()):
+ for symbol in section.iter_symbols():
if symbol['st_shndx'] != "SHN_ABS":
continue
@@ -206,7 +206,6 @@
def main():
parse_args()
- linker_file = args.output
partitions = {}
if args.directory is not None:
diff --git a/scripts/gen_priv_stacks.py b/scripts/gen_priv_stacks.py
index 73e0d89..670d09e 100755
--- a/scripts/gen_priv_stacks.py
+++ b/scripts/gen_priv_stacks.py
@@ -79,14 +79,14 @@
# priv stack declarations
fp.write("%{\n")
fp.write(includes)
- for obj_addr, ko in objs.items():
+ for obj_addr in objs:
fp.write(priv_stack_decl_temp % (obj_addr))
fp.write("%}\n")
# structure declaration
fp.write(structure)
- for obj_addr, ko in objs.items():
+ for obj_addr in objs:
byte_str = struct.pack("<I" if eh.little_endian else ">I", obj_addr)
fp.write("\"")
for byte in byte_str:
diff --git a/scripts/gen_relocate_app.py b/scripts/gen_relocate_app.py
index aa5ff5a..7d1ecbb 100644
--- a/scripts/gen_relocate_app.py
+++ b/scripts/gen_relocate_app.py
@@ -292,7 +292,7 @@
# get the object file name which is almost always pended with .obj
obj_filename = filename.split("/")[-1] + ".obj"
- for dirpath, dirs, files in os.walk(searchpath):
+ for dirpath, _, files in os.walk(searchpath):
for filename1 in files:
if filename1 == obj_filename:
if filename.split("/")[-2] in dirpath.split("/")[-1]:
diff --git a/scripts/kconfig/checkconfig.py b/scripts/kconfig/checkconfig.py
index e4013e7..90da931 100755
--- a/scripts/kconfig/checkconfig.py
+++ b/scripts/kconfig/checkconfig.py
@@ -104,7 +104,7 @@
fname.endswith(".S")):
with open(os.path.join(dirName, fname), "r", encoding="utf-8", errors="ignore") as f:
searchConf = f.readlines()
- for i, line in enumerate(searchConf):
+ for line in searchConf:
if re.search('(^|[\s|(])CONFIG_([a-zA-Z0-9_]+)', line) :
configName = re.search('(^|[\s|(])'
+'CONFIG_([a-zA-Z0-9_]+)', line)
diff --git a/scripts/mergehex.py b/scripts/mergehex.py
index 8e06638..bf23cb2 100644
--- a/scripts/mergehex.py
+++ b/scripts/mergehex.py
@@ -26,7 +26,7 @@
try:
ih.merge(to_merge)
- except AddressOverlapError as e:
+ except AddressOverlapError:
raise AddressOverlapError("{} has merge issues".format(hex_file_path))
print("Merged {}".format(hex_file_path))
diff --git a/scripts/sanity_chk/harness.py b/scripts/sanity_chk/harness.py
index b8234b2..d7cf51b 100644
--- a/scripts/sanity_chk/harness.py
+++ b/scripts/sanity_chk/harness.py
@@ -56,7 +56,7 @@
if self.ordered:
ordered = True
pos = 0
- for k,v in self.matches.items():
+ for k in self.matches:
if k != self.regex[pos]:
ordered = False
pos += 1