From: Leonid Vasiliev <lvasiliev@tarantool.org> To: sergeyb@tarantool.org, tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org, imun@tarantool.org Cc: alexander.turenko@tarantool.org Subject: Re: [Tarantool-patches] [PATCH 2/4] test: make dict.items() compatible with Python 3.x Date: Tue, 15 Dec 2020 15:40:59 +0300 [thread overview] Message-ID: <1fb05971-8981-7acc-b43a-fcfb2d803af8@tarantool.org> (raw) In-Reply-To: <ee4997f4d2c375580a08b0fab5a0122e23db4bff.1607675470.git.sergeyb@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 <sergeyb@tarantool.org> > > 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) >
next prev parent reply other threads:[~2020-12-15 12:41 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <cover.1607675470.git.sergeyb@tarantool.org> 2020-12-11 8:42 ` [Tarantool-patches] [PATCH 1/4] test: convert print to function and make quotes use consistent sergeyb 2020-12-13 17:58 ` Vladislav Shpilevoy 2020-12-14 11:44 ` Sergey Bronnikov 2020-12-15 10:05 ` Leonid Vasiliev 2020-12-15 11:51 ` Sergey Bronnikov 2020-12-20 16:47 ` Vladislav Shpilevoy 2020-12-23 12:34 ` Sergey Bronnikov 2020-12-11 8:42 ` [Tarantool-patches] [PATCH 2/4] test: make dict.items() compatible with Python 3.x sergeyb 2020-12-13 17:58 ` Vladislav Shpilevoy 2020-12-15 12:40 ` Leonid Vasiliev [this message] 2020-12-11 8:42 ` [Tarantool-patches] [PATCH 3/4] test: make convert to hex " sergeyb 2020-12-15 11:55 ` Leonid Vasiliev 2020-12-16 14:04 ` Sergey Bronnikov 2020-12-17 18:26 ` Leonid Vasiliev 2020-12-22 8:15 ` [Tarantool-patches] [PATCH] test: make strings compatible with Python 3 sergeyb 2020-12-23 9:59 ` Leonid Vasiliev 2020-12-23 10:35 ` Sergey Bronnikov 2020-12-23 11:09 ` Leonid Vasiliev 2020-12-22 8:19 ` [Tarantool-patches] [PATCH 3/4] test: make convert to hex compatible with Python 3.x Sergey Bronnikov 2020-12-23 10:00 ` Leonid Vasiliev 2020-12-11 8:42 ` [Tarantool-patches] [PATCH 4/4] test: remove dead code in Python tests end extra newline sergeyb 2020-12-15 12:51 ` Leonid Vasiliev 2020-12-15 13:00 ` Sergey Bronnikov 2020-12-13 19:02 ` [Tarantool-patches] [PATCH v3 0/4] Support Python 3 in tests and PEPify source code Sergey Bronnikov 2020-12-23 10:07 ` Leonid Vasiliev 2020-12-23 12:42 ` Sergey Bronnikov 2020-12-23 23:51 ` Leonid Vasiliev
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1fb05971-8981-7acc-b43a-fcfb2d803af8@tarantool.org \ --to=lvasiliev@tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=imun@tarantool.org \ --cc=sergeyb@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 2/4] test: make dict.items() compatible with Python 3.x' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox