Skip to content

Commit

Permalink
style: Fix incorrect-dict-iterator (PERF102) (OSGeo#4007)
Browse files Browse the repository at this point in the history
When iterating over a dictionary with dict.items() but discarding either the values or the keys, dict.values() or dict.keys() should be used instead
  • Loading branch information
echoix authored Jul 9, 2024
1 parent 4be87a1 commit f4a407f
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gui/wxpython/dbmgr/sqlbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def OnAddMark(self, event):
elif self.btn_arithmeticpanel and self.btn_arithmeticpanel.IsShown():
btns = self.btn_arithmetic

for key, value in btns.items():
for value in btns.values():
if event.GetId() == value[1]:
mark = value[0]
break
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/iscatt/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def CleanUp(self):
self.core.CleanUp()

def CleanUpDone(self):
for scatt_id, scatt in self.plots.items():
for scatt in self.plots.values():
if scatt["scatt"]:
scatt["scatt"].CleanUp()

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def OnPageChange(self, event=None):
"""Go to next page"""
if event.GetDirection():
self.p4projparams = ""
for id, param in self.pparam.items():
for param in self.pparam.values():
if param["type"] == "bool":
if param["value"] is False:
continue
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/mapwin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def UnregisterAllHandlers(self):
Before each handler is unregistered it is called with string
value "unregistered" of event parameter.
"""
for containerEv, handlers in self.handlersContainer.items():
for handlers in self.handlersContainer.values():
for handler in handlers:
try:
handler("unregistered")
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ ignore = [
"FURB192", # sorted-min-max
"I001", # unsorted-imports
"ISC003", # explicit-string-concatenation
"PERF102", # incorrect-dict-iterator
"PERF203", # try-except-in-loop
"PERF401", # manual-list-comprehension
"PERF402", # manual-list-copy
Expand Down
2 changes: 1 addition & 1 deletion python/grass/jupyter/seriesmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def save(
self.render()

tmp_files = []
for _, file in self._base_filename_dict.items():
for file in self._base_filename_dict.values():
tmp_files.append(file)

save_gif(
Expand Down
2 changes: 1 addition & 1 deletion python/grass/jupyter/tests/seriesmap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_render_layers(space_time_raster_dataset):
# check files exist
# We need to check values which are only in protected attributes
# pylint: disable=protected-access
for unused_layer, filename in img._base_filename_dict.items():
for filename in img._base_filename_dict.values():
assert Path(filename).is_file()


Expand Down
2 changes: 1 addition & 1 deletion python/grass/jupyter/tests/timeseriesmap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_render_layers(space_time_raster_dataset, fill_gaps):
# check files exist
# We need to check values which are only in protected attributes
# pylint: disable=protected-access
for unused_date, filename in img._base_filename_dict.items():
for filename in img._base_filename_dict.values():
assert Path(filename).is_file()


Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/tests/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def print_test(testdict):
print(execmode)
for oper, operdict in operation.items():
print(" ", oper)
for key, value in operdict.items():
for key in operdict.keys():
print(" ", key)


Expand Down
2 changes: 1 addition & 1 deletion python/grass/script/testsuite/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
os.environ[k] = v

def tearDown(self):
for k, v in self.env.items():
for k in self.env.keys():
oval = self.original_env[k]
if oval == self.NOT_FOUND:
os.environ.pop(k)
Expand Down
2 changes: 1 addition & 1 deletion scripts/v.pack/v.pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def main():
else:
# for each layer connection save a table in sqlite database
sqlitedb = os.path.join(basedir, "db.sqlite")
for i, dbconn in db_vect.items():
for dbconn in db_vect.values():
grass.run_command(
"db.copy",
from_driver=dbconn["driver"],
Expand Down

0 comments on commit f4a407f

Please sign in to comment.