Skip to content

Commit

Permalink
Fix some inefficient python dictionary iteration
Browse files Browse the repository at this point in the history
(cherry picked from commit f3e9aaf)
  • Loading branch information
nyalldawson committed Oct 30, 2018
1 parent ef1cf09 commit 29c2598
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_plugins/html_elems.py
Expand Up @@ -77,7 +77,7 @@ def setAttr(self, name, value):

def getAttrsHtml(self):
html = u''
for k, v in list(self.attrs.items()):
for k, v in self.attrs.items():
html += u' %s="%s"' % (k, v)
return html

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_plugins/vlayers/connector.py
Expand Up @@ -193,7 +193,7 @@ def getVectorTables(self, schema=None):
reg = VLayerRegistry.instance()
VLayerRegistry.instance().reset()
lst = []
for _, l in list(QgsProject.instance().mapLayers().items()):
for _, l in QgsProject.instance().mapLayers():
if l.type() == QgsMapLayer.VectorLayer:

lname = l.name()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/dlg_sql_window.py
Expand Up @@ -532,7 +532,7 @@ def initCompleter(self):
dictionary = getSqlDictionary()

wordlist = []
for name, value in list(dictionary.items()):
for _, value in dictionary.items():
wordlist += value # concat lists
wordlist = list(set(wordlist)) # remove duplicates

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/ext/v_net.py
Expand Up @@ -96,7 +96,7 @@ def variableOutput(alg, layers, parameters, context, nocats=True):
:param context:
:param nocats: do not add categories.
"""
for outputName, typeList in list(layers.items()):
for outputName, typeList in layers.items():
if not isinstance(typeList, list):
continue

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/ConcaveHull.py
Expand Up @@ -127,7 +127,7 @@ def processAlgorithm(self, parameters, context, feedback):
counter = 50. / len(edges)
i = 0
ids = []
for id, max_len in list(edges.items()):
for id, max_len in edges.items():
if feedback.isCanceled():
break

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/HypsometricCurves.py
Expand Up @@ -225,7 +225,7 @@ def calculateHypsometry(self, fid, fName, feedback, data, pX, pY,
else:
multiplier = pX * pY

for k, v in list(out.items()):
for k, v in out.items():
out[k] = v * multiplier

prev = None
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/algs/qgis/PointsToPaths.py
Expand Up @@ -144,10 +144,10 @@ def processAlgorithm(self, parameters, context, feedback):

point = f.geometry().constGet().clone()
if group_field_index >= 0:
group = f[group_field_index] # (1)
group = f[group_field_index]
else:
group = 1
order = f[order_field_index] # (1)
order = f[order_field_index]
if date_format != '':
order = datetime.strptime(str(order), date_format)
if group in points:
Expand All @@ -165,8 +165,7 @@ def processAlgorithm(self, parameters, context, feedback):

current = 0
total = 100.0 / len(points) if points else 1
verlist = list(points.items()) # (2)
for group, vertices in vertlist: # (2)
for group, vertices in points.items():
if feedback.isCanceled():
break

Expand Down
Expand Up @@ -242,7 +242,7 @@ class FieldTypeDelegate(QStyledItemDelegate):

def createEditor(self, parent, option, index):
editor = QComboBox(parent)
for key, text in list(FieldsMappingModel.fieldTypes.items()):
for key, text in FieldsMappingModel.fieldTypes.items():
editor.addItem(text, key)
return editor

Expand Down
Expand Up @@ -324,7 +324,7 @@ def setPreviousValues(self):
value = value.staticValue()
wrapper.setValue(value)

for name, out in list(alg.modelOutputs().items()):
for name, out in alg.modelOutputs().items():
if out.childOutputName() in self.valueItems:
self.valueItems[out.childOutputName()].setText(out.name())

Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/modeler/ModelerScene.py
Expand Up @@ -47,16 +47,16 @@ def __init__(self, parent=None, dialog=None):
self.dialog = dialog

def getParameterPositions(self):
return {key: item.pos() for key, item in list(self.paramItems.items())}
return {key: item.pos() for key, item in self.paramItems.items()}

def getAlgorithmPositions(self):
return {key: item.pos() for key, item in list(self.algItems.items())}
return {key: item.pos() for key, item in self.algItems.items()}

def getOutputPositions(self):
pos = {}
for algName, outputs in list(self.outputItems.items()):
for algName, outputs in self.outputItems.items():
outputPos = {}
for (key, value) in list(outputs.items()):
for key, value in outputs.items():
if value is not None:
outputPos[key] = value.pos()
else:
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/tests/AlgorithmsTestBase.py
Expand Up @@ -107,7 +107,7 @@ def check_algorithm(self, name, defs):
for param in zip(alg.parameterDefinitions(), params):
parameters[param[0].name()] = param[1]
else:
for k, p in list(params.items()):
for k, p in params.items():
parameters[k] = p

for r, p in list(defs['results'].items()):
Expand Down Expand Up @@ -157,7 +157,7 @@ def load_params(self, params):
if isinstance(params, list):
return [self.load_param(p) for p in params]
elif isinstance(params, dict):
return {key: self.load_param(p, key) for key, p in list(params.items())}
return {key: self.load_param(p, key) for key, p in params.items()}
else:
return params

Expand Down Expand Up @@ -274,7 +274,7 @@ def check_results(self, results, context, params, expected):
"""
Checks if result produced by an algorithm matches with the expected specification.
"""
for id, expected_result in list(expected.items()):
for id, expected_result in expected.items():
if expected_result['type'] in ('vector', 'table'):
if 'compare' in expected_result and not expected_result['compare']:
# skipping the comparison, so just make sure output is valid
Expand Down

0 comments on commit 29c2598

Please sign in to comment.