Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some inefficient python dictionary iteration
  • Loading branch information
nyalldawson committed Oct 30, 2018
1 parent 85efc77 commit f3e9aaf
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): def getAttrsHtml(self):
html = u'' html = u''
for k, v in list(self.attrs.items()): for k, v in self.attrs.items():
html += u' %s="%s"' % (k, v) html += u' %s="%s"' % (k, v)
return html 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() reg = VLayerRegistry.instance()
VLayerRegistry.instance().reset() VLayerRegistry.instance().reset()
lst = [] lst = []
for _, l in list(QgsProject.instance().mapLayers().items()): for _, l in QgsProject.instance().mapLayers():
if l.type() == QgsMapLayer.VectorLayer: if l.type() == QgsMapLayer.VectorLayer:


lname = l.name() 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() dictionary = getSqlDictionary()


wordlist = [] wordlist = []
for name, value in list(dictionary.items()): for _, value in dictionary.items():
wordlist += value # concat lists wordlist += value # concat lists
wordlist = list(set(wordlist)) # remove duplicates 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 context:
:param nocats: do not add categories. :param nocats: do not add categories.
""" """
for outputName, typeList in list(layers.items()): for outputName, typeList in layers.items():
if not isinstance(typeList, list): if not isinstance(typeList, list):
continue 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) counter = 50. / len(edges)
i = 0 i = 0
ids = [] ids = []
for id, max_len in list(edges.items()): for id, max_len in edges.items():
if feedback.isCanceled(): if feedback.isCanceled():
break 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: else:
multiplier = pX * pY multiplier = pX * pY


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


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


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


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


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


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


for name, out in list(alg.modelOutputs().items()): for name, out in alg.modelOutputs().items():
if out.childOutputName() in self.valueItems: if out.childOutputName() in self.valueItems:
self.valueItems[out.childOutputName()].setText(out.name()) 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 self.dialog = dialog


def getParameterPositions(self): 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): 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): def getOutputPositions(self):
pos = {} pos = {}
for algName, outputs in list(self.outputItems.items()): for algName, outputs in self.outputItems.items():
outputPos = {} outputPos = {}
for (key, value) in list(outputs.items()): for key, value in outputs.items():
if value is not None: if value is not None:
outputPos[key] = value.pos() outputPos[key] = value.pos()
else: 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): for param in zip(alg.parameterDefinitions(), params):
parameters[param[0].name()] = param[1] parameters[param[0].name()] = param[1]
else: else:
for k, p in list(params.items()): for k, p in params.items():
parameters[k] = p parameters[k] = p


for r, p in list(defs['results'].items()): 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): if isinstance(params, list):
return [self.load_param(p) for p in params] return [self.load_param(p) for p in params]
elif isinstance(params, dict): 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: else:
return params 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. 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 expected_result['type'] in ('vector', 'table'):
if 'compare' in expected_result and not expected_result['compare']: if 'compare' in expected_result and not expected_result['compare']:
# skipping the comparison, so just make sure output is valid # skipping the comparison, so just make sure output is valid
Expand Down

0 comments on commit f3e9aaf

Please sign in to comment.