[Tarantool-patches] [PATCH v3 2/5] test: make dict.items() compatible with Python 3.x

sergeyb at tarantool.org sergeyb at tarantool.org
Wed Dec 23 15:36:06 MSK 2020


From: Sergey Bronnikov <sergeyb at tarantool.org>

In Python 2.x calling items() makes a copy of the keys that you can
iterate over while modifying the dict. This doesn't work in Python 3.x
because items() returns an iterator instead of a list and Python 3 raise
an exception "dictionary changed size during iteration". To workaround
it one can use list to force a copy of the keys to be made.

Part of #5538
---
 test/box-py/iproto.test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/box-py/iproto.test.py b/test/box-py/iproto.test.py
index 6ed49051b..6723e03f5 100644
--- a/test/box-py/iproto.test.py
+++ b/test/box-py/iproto.test.py
@@ -37,7 +37,7 @@ print(iproto.py_con.ping() > 0)
 s.close()
 
 key_names = {}
-for (k,v) in globals().items():
+for (k,v) in list(globals().items()):
     if type(k) == str and k.startswith("IPROTO_") and type(v) == int:
         key_names[v] = k
 
-- 
2.25.1



More information about the Tarantool-patches mailing list