Skip to content

Commit

Permalink
replace all dict.iteritems() with dict.items()
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zero committed Aug 31, 2018
1 parent 25da970 commit 56d5000
Show file tree
Hide file tree
Showing 64 changed files with 164 additions and 164 deletions.
4 changes: 2 additions & 2 deletions .ci/test_daemon.py
Expand Up @@ -79,7 +79,7 @@ def print_logshow(pk):
def validate_calculations(expected_results):
valid = True
actual_dict = {}
for pk, expected_dict in expected_results.iteritems():
for pk, expected_dict in expected_results.items():
calc = load_node(pk)
if not calc.is_finished_ok:
print('Calculation<{}> not finished ok: process_state<{}> exit_status<{}>'
Expand Down Expand Up @@ -110,7 +110,7 @@ def validate_calculations(expected_results):

def validate_workchains(expected_results):
valid = True
for pk, expected_value in expected_results.iteritems():
for pk, expected_value in expected_results.items():
this_valid = True
try:
calc = load_node(pk)
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/djsite/cmdline.py
Expand Up @@ -24,7 +24,7 @@ def get_group_list(user, type_string, n_days_ago=None,
name_filters={}):
from aiida.orm.implementation.django.group import Group

name_filters = {"name__" + k: v for (k, v) in name_filters.iteritems() if v}
name_filters = {"name__" + k: v for (k, v) in name_filters.items() if v}

if n_days_ago:
n_days_ago = timezone.now() - datetime.timedelta(days=n_days_ago)
Expand Down
22 changes: 11 additions & 11 deletions aiida/backends/djsite/db/models.py
Expand Up @@ -375,7 +375,7 @@ def _deserialize_attribute(mainitem, subitems, sep, original_class=None,
# subitems contains all subitems, here I store only those of
# deepness 1, i.e. if I have subitems '0', '1' and '1.c' I
# store only '0' and '1'
firstlevelsubdict = {k: v for k, v in subitems.iteritems()
firstlevelsubdict = {k: v for k, v in subitems.items()
if sep not in k}

# For checking, I verify the expected values
Expand Down Expand Up @@ -427,10 +427,10 @@ def _deserialize_attribute(mainitem, subitems, sep, original_class=None,

# I get the values in memory as a dictionary
tempdict = {}
for firstsubk, firstsubv in firstlevelsubdict.iteritems():
for firstsubk, firstsubv in firstlevelsubdict.items():
# I call recursively the same function to get subitems
newsubitems = {k[len(firstsubk) + len(sep):]: v
for k, v in subitems.iteritems()
for k, v in subitems.items()
if k.startswith(firstsubk + sep)}
tempdict[firstsubk] = _deserialize_attribute(mainitem=firstsubv,
subitems=newsubitems, sep=sep, original_class=original_class,
Expand All @@ -443,7 +443,7 @@ def _deserialize_attribute(mainitem, subitems, sep, original_class=None,
# subitems contains all subitems, here I store only those of
# deepness 1, i.e. if I have subitems '0', '1' and '1.c' I
# store only '0' and '1'
firstlevelsubdict = {k: v for k, v in subitems.iteritems()
firstlevelsubdict = {k: v for k, v in subitems.items()
if sep not in k}

if len(firstlevelsubdict) != mainitem['ival']:
Expand Down Expand Up @@ -472,10 +472,10 @@ def _deserialize_attribute(mainitem, subitems, sep, original_class=None,

# I get the values in memory as a dictionary
tempdict = {}
for firstsubk, firstsubv in firstlevelsubdict.iteritems():
for firstsubk, firstsubv in firstlevelsubdict.items():
# I call recursively the same function to get subitems
newsubitems = {k[len(firstsubk) + len(sep):]: v
for k, v in subitems.iteritems()
for k, v in subitems.items()
if k.startswith(firstsubk + sep)}
tempdict[firstsubk] = _deserialize_attribute(mainitem=firstsubv,
subitems=newsubitems, sep=sep, original_class=original_class,
Expand Down Expand Up @@ -527,11 +527,11 @@ def deserialize_attributes(data, sep, original_class=None, original_pk=None):
# I group results by zero-level entity
found_mainitems = {}
found_subitems = defaultdict(dict)
for mainkey, descriptiondict in data.iteritems():
for mainkey, descriptiondict in data.items():
prefix, thissep, postfix = mainkey.partition(sep)
if thissep:
found_subitems[prefix][postfix] = {k: v for k, v
in descriptiondict.iteritems() if k != "key"}
in descriptiondict.items() if k != "key"}
else:
mainitem = descriptiondict.copy()
mainitem['key'] = prefix
Expand All @@ -546,7 +546,7 @@ def deserialize_attributes(data, sep, original_class=None, original_pk=None):

# For each zero-level entity, I call the _deserialize_attribute function
retval = {}
for k, v in found_mainitems.iteritems():
for k, v in found_mainitems.items():
# Note: found_subitems[k] will return an empty dictionary it the
# key does not exist, as it is a defaultdict
retval[k] = _deserialize_attribute(mainitem=v,
Expand Down Expand Up @@ -835,7 +835,7 @@ def create_value(cls, key, value, subspecifier_value=None,
new_entry.ival = len(value)
new_entry.fval = None

for subk, subv in value.iteritems():
for subk, subv in value.items():
cls.validate_key(subk)

# I do not need get_or_create here, because
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def reset_values_for_node(cls, dbnode, attributes, with_transaction=True,
dbnode_node = dbnode

# create_value returns a list of nodes to store
for k, v in attributes.iteritems():
for k, v in attributes.items():
nodes_to_store.extend(
cls.create_value(k, v,
subspecifier_value=dbnode_node,
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/djsite/db/subtests/nodes.py
Expand Up @@ -260,10 +260,10 @@ def test_replace_extras_2(self):
'list': 66.3,
}

for k, v in extras_to_set.iteritems():
for k, v in extras_to_set.items():
a.set_extra(k, v)

for k, v in new_extras.iteritems():
for k, v in new_extras.items():
# I delete one by one the keys and check if the operation is
# performed correctly
a.set_extra(k, v)
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/general/abstractqueries.py
Expand Up @@ -142,7 +142,7 @@ def count_statistics(dataset):
def get_statistics_dict(dataset):
results = {}
for count, typestring in sorted(
(v, k) for k, v in dataset.iteritems())[::-1]:
(v, k) for k, v in dataset.items())[::-1]:
results[typestring] = count
return results

Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/models/workflow.py
Expand Up @@ -236,7 +236,7 @@ def get_or_create(self, **kwargs): # this is to emulate the django method
if instance:
return instance, False
else:
params = dict((k, v) for k, v in kwargs.iteritems() if not isinstance(v, ClauseElement))
params = dict((k, v) for k, v in kwargs.items() if not isinstance(v, ClauseElement))
instance = model(**params)
session.add(instance)
return instance, True
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/sqlalchemy/utils.py
Expand Up @@ -110,7 +110,7 @@ def f(v):
if isinstance(v, list):
return [f(_) for _ in v]
elif isinstance(v, dict):
return dict((key, f(val)) for key, val in v.iteritems())
return dict((key, f(val)) for key, val in v.items())
elif isinstance(v, datetime.datetime):
return v.isoformat()
return v
Expand All @@ -134,7 +134,7 @@ def f(d):
d[i] = f(val)
return d
elif isinstance(d, dict):
for k, v in d.iteritems():
for k, v in d.items():
d[k] = f(v)
return d
elif isinstance(d, basestring):
Expand Down
8 changes: 4 additions & 4 deletions aiida/backends/tests/__init__.py
Expand Up @@ -162,10 +162,10 @@ def get_db_test_list():
raise ConfigurationError("A 'common' key must always be defined!")

retdict = defaultdict(list)
for k, tests in common_tests.iteritems():
for k, tests in common_tests.items():
for t in tests:
retdict[k].append(t)
for k, tests in be_tests.iteritems():
for k, tests in be_tests.items():
for t in tests:
retdict[k].append(t)

Expand All @@ -177,9 +177,9 @@ def get_db_test_list():
# Explode the dictionary so that if I have a.b.c,
# I can run it also just with 'a' or with 'a.b'
final_retdict = defaultdict(list)
for k, v in retdict.iteritems():
for k, v in retdict.items():
final_retdict[k] = v
for k, v in retdict.iteritems():
for k, v in retdict.items():
if '.' in k:
parts = k.split('.')
for last_idx in range(1, len(parts)):
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/calculation_node.py
Expand Up @@ -65,7 +65,7 @@ def test_calculation_updatable_attribute(self):
'state': self.stateval
}

for k, v in attrs_to_set.iteritems():
for k, v in attrs_to_set.items():
a._set_attr(k, v)

# Check before storing
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/tests/cmdline/commands/test_computer.py
Expand Up @@ -61,7 +61,7 @@ def generate_setup_options(ordereddict):
:return: a list to be passed as command-line arguments.
"""
options = []
for key, value in ordereddict.iteritems():
for key, value in ordereddict.items():
if value is None:
options.append('--{}'.format(key))
else:
Expand All @@ -81,7 +81,7 @@ def generate_setup_options_interactive(ordereddict):
:return: a list to be passed as command-line arguments.
"""
options = []
for key, value in ordereddict.iteritems():
for key, value in ordereddict.items():
if value is None:
options.append(True)
else:
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/export_and_import.py
Expand Up @@ -974,7 +974,7 @@ def test_complex_graph_import_export(self):

import_data(filename, silent=True, ignore_unknown_nodes=True)

for uuid, label in node_uuids_labels.iteritems():
for uuid, label in node_uuids_labels.items():
try:
load_node(uuid)
except NotExistent:
Expand Down
20 changes: 10 additions & 10 deletions aiida/backends/tests/nodes.py
Expand Up @@ -607,7 +607,7 @@ def test_attributes_on_clone(self):
'emptylist': [],
}

for k, v in attrs_to_set.iteritems():
for k, v in attrs_to_set.items():
a._set_attr(k, v)

# Create a copy
Expand Down Expand Up @@ -1020,7 +1020,7 @@ def test_attr_listing(self):
'list': self.listval,
}

for k, v in attrs_to_set.iteritems():
for k, v in attrs_to_set.items():
a._set_attr(k, v)

a.store()
Expand All @@ -1031,7 +1031,7 @@ def test_attr_listing(self):
'some_other_name': 987
}

for k, v in extras_to_set.iteritems():
for k, v in extras_to_set.items():
a.set_extra(k, v)

all_extras = dict(_aiida_hash=AnyValue(), **extras_to_set)
Expand Down Expand Up @@ -1059,14 +1059,14 @@ def test_versioning(self):
'list': self.listval,
}

for key, value in attrs_to_set.iteritems():
for key, value in attrs_to_set.items():
a._set_attr(key, value)
self.assertEquals(a.get_attr(key), value)

a.store()

# Check after storing
for key, value in attrs_to_set.iteritems():
for key, value in attrs_to_set.items():
self.assertEquals(a.get_attr(key), value)

# Even if I stored many attributes, this should stay at 1
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def test_delete_extras(self):

all_extras = dict(_aiida_hash=AnyValue(), **extras_to_set)

for k, v in extras_to_set.iteritems():
for k, v in extras_to_set.items():
a.set_extra(k, v)

self.assertEquals({k: v for k, v in a.iterextras()}, all_extras)
Expand Down Expand Up @@ -1154,12 +1154,12 @@ def test_replace_extras_1(self):
'list': 66.3,
}

for k, v in extras_to_set.iteritems():
for k, v in extras_to_set.items():
a.set_extra(k, v)

self.assertEquals({k: v for k, v in a.iterextras()}, all_extras)

for k, v in new_extras.iteritems():
for k, v in new_extras.items():
# I delete one by one the keys and check if the operation is
# performed correctly
a.set_extra(k, v)
Expand Down Expand Up @@ -1967,11 +1967,11 @@ def test_link_with_unstored(self):
n2.store_all()
n3.store_all()

n2_in_links = [(l, n.uuid) for l, n in n2.get_inputs_dict().iteritems()]
n2_in_links = [(l, n.uuid) for l, n in n2.get_inputs_dict().items()]
self.assertEquals(sorted(n2_in_links), sorted([
('l1', n1.uuid),
]))
n3_in_links = [(l, n.uuid) for l, n in n3.get_inputs_dict().iteritems()]
n3_in_links = [(l, n.uuid) for l, n in n3.get_inputs_dict().items()]
self.assertEquals(
sorted(n3_in_links), sorted([
('l2', n2.uuid),
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/orm/data/frozendict.py
Expand Up @@ -30,7 +30,7 @@ def test_get_value(self):
def test_iterate(self):
input = {'a': Int(5).store(), 'b': Str('testing').store()}
d = FrozenDict(dict=input)
for k, v in d.iteritems():
for k, v in d.items():
self.assertEqual(input[k], v)

def test_length(self):
Expand Down
8 changes: 4 additions & 4 deletions aiida/backends/tests/query.py
Expand Up @@ -981,10 +981,10 @@ def store_and_add(n, statistics):

new_db_statistics = qmanager.get_creation_statistics()
# I only check a few fields
new_db_statistics = {k: v for k, v in new_db_statistics.iteritems() if k in expected_db_statistics}
new_db_statistics = {k: v for k, v in new_db_statistics.items() if k in expected_db_statistics}

expected_db_statistics = {k: dict(v) if isinstance(v, defaultdict) else v
for k, v in expected_db_statistics.iteritems()}
for k, v in expected_db_statistics.items()}

self.assertEquals(new_db_statistics, expected_db_statistics)

Expand Down Expand Up @@ -1030,9 +1030,9 @@ class QueryManagerDefault(AbstractQueryManager):

new_db_statistics = qmanager_default.get_creation_statistics()
# I only check a few fields
new_db_statistics = {k: v for k, v in new_db_statistics.iteritems() if k in expected_db_statistics}
new_db_statistics = {k: v for k, v in new_db_statistics.items() if k in expected_db_statistics}

expected_db_statistics = {k: dict(v) if isinstance(v, defaultdict) else v
for k, v in expected_db_statistics.iteritems()}
for k, v in expected_db_statistics.items()}

self.assertEquals(new_db_statistics, expected_db_statistics)
2 changes: 1 addition & 1 deletion aiida/backends/tests/restapi.py
Expand Up @@ -172,7 +172,7 @@ def process_dummy_data(cls):
'structuredata': StructureData,
'data': Data,
}
for label, dataclass in data_types.iteritems():
for label, dataclass in data_types.items():
data = QueryBuilder().append(dataclass, tag="data", project=data_projections).order_by(
{'data': [{'id': {'order': 'desc'}}]}).dict()
data = [_['data'] for _ in data]
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/work/process.py
Expand Up @@ -105,7 +105,7 @@ def test_input_link_creation(self):
inputs['store_provenance'] = True
p = test_utils.DummyProcess(inputs)

for label, value in p._calc.get_inputs_dict().iteritems():
for label, value in p._calc.get_inputs_dict().items():
self.assertTrue(label in inputs)
self.assertEqual(int(label), int(value.value))
dummy_inputs.remove(label)
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/work/test_process_builder.py
Expand Up @@ -47,7 +47,7 @@ def test_process_builder_attributes(self):
"""
Check that the builder has all the input ports of the process class as attributes
"""
for name, port in self.process_class.spec().inputs.iteritems():
for name, port in self.process_class.spec().inputs.items():
self.assertTrue(hasattr(self.builder, name))

def test_process_builder_set_attributes(self):
Expand Down

0 comments on commit 56d5000

Please sign in to comment.