From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5117345C304 for ; Tue, 15 Dec 2020 15:41:59 +0300 (MSK) References: From: Leonid Vasiliev Message-ID: <1fb05971-8981-7acc-b43a-fcfb2d803af8@tarantool.org> Date: Tue, 15 Dec 2020 15:40:59 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH 2/4] test: make dict.items() compatible with Python 3.x List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: sergeyb@tarantool.org, tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org, imun@tarantool.org Cc: alexander.turenko@tarantool.org Hi! Thank you for the patch. Current patch(AFAIU): test: make dict.items() compatible with Python 3.x 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 f9ecd7a22fcb148c60867e7d1fcd02b1a6fda9fc 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 6ed4905..6723e03 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 if I understand correctly- LGTM. On 11.12.2020 11:42, Sergey Bronnikov via Tarantool-patches wrote: > From: Sergey Bronnikov > > In Python 2.x calling keys makes a copy of the key that you can iterate over > while modifying the dict. This doesn't work in Python 3.x because keys returns > an iterator instead of a list. 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 5eccd40d3..25ead43c4 100644 > --- a/test/box-py/iproto.test.py > +++ b/test/box-py/iproto.test.py > @@ -39,7 +39,7 @@ for (k,v) in list(globals().items()): > > def repr_dict(todump): > d = {} > - for (k, v) in list(todump.items()): > + for (k, v) in todump.items(): > k_name = key_names.get(k, k) > d[k_name] = v > return repr(d) >