Skip to content
Permalink
Browse files

Fix some inefficient python dictionary iteration

  • Loading branch information
nyalldawson committed Oct 30, 2018
1 parent 85efc77 commit f3e9aaf79a9282b28a605abd0dadaab9951050c8
@@ -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

@@ -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()
@@ -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

@@ -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

@@ -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

@@ -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
@@ -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:
@@ -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

@@ -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

@@ -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())

@@ -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:
@@ -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()):
@@ -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

@@ -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

0 comments on commit f3e9aaf

Please sign in to comment.
You can’t perform that action at this time.