Commit 7851a964 authored by Kirill Smelkov's avatar Kirill Smelkov

*: dict.keys() returns sequence, not [] on py3

The sequence cannot be randomly accessed, e.g.

    In [5]: d = {1:2}

    In [6]: kv = d.keys()

    In [7]: kv
    Out[7]: dict_keys([1])

    In [8]: kv[0]
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-8-643f90e1910b> in <module>()
    ----> 1 kv[0]

    TypeError: 'dict_keys' object is not subscriptable

-> Use list(dict.keys()) in places where we need random access.
parent 2f9e0623
...@@ -113,7 +113,7 @@ def ext4subj(subj): ...@@ -113,7 +113,7 @@ def ext4subj(subj):
d[xcookie] = cookie d[xcookie] = cookie
# shufle extension dict randomly - to likely trigger different ordering on save # shufle extension dict randomly - to likely trigger different ordering on save
keyv = d.keys() keyv = list(d.keys())
random.shuffle(keyv) random.shuffle(keyv)
ext = {} ext = {}
for key in keyv: for key in keyv:
...@@ -227,7 +227,7 @@ def _gen_testdb(outfs_path, zext): ...@@ -227,7 +227,7 @@ def _gen_testdb(outfs_path, zext):
break break
# delete an object # delete an object
name = random.choice(root.keys()) name = random.choice(list(root.keys()))
obj = root[name] obj = root[name]
root[name] = Object("%s%i*" % (name, i)) root[name] = Object("%s%i*" % (name, i))
# NOTE user/ext are kept empty on purpose - to also test this case # NOTE user/ext are kept empty on purpose - to also test this case
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment