From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Cc: openembedded-core@lists.openembedded.org
Subject: Re: [PATCH 01/16] scripts: python3: convert iterables to lists
Date: Thu, 2 Jun 2016 18:04:30 +0300 [thread overview]
Message-ID: <20160602150430.GA21917@linux.intel.com> (raw)
In-Reply-To: <1d8f0b7c-b094-23cd-ff7e-320d919dba62@linux.intel.com>
On Thu, Jun 02, 2016 at 08:55:21AM -0500, Leonardo Sandoval wrote:
> Ed,
>
> what is the reason for this change?
>
The reason is that in python 3 dict.keys() returns iterator unlike in
pyton 2 where it returns list. If dictionary is changed inside the loop
(which is the case here) "RuntimeError: dictionary changed size during iteration" will be raised.
Another case is when result of dict.keys() is added to the list. This
kind of operations would raise TypeError: unsupported operand type(s)
for +: 'dict_keys' and 'list'
>
> On 06/02/2016 05:12 AM, Ed Bartosh wrote:
> >Converted return value of items() keys() and values() to
> >lists when dictionary is modified in the loop and when
> >the result is added to the list.
> >
> >Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
> >---
> > scripts/bitbake-whatchanged | 6 +++---
> > scripts/combo-layer | 2 +-
> > scripts/lib/devtool/build.py | 2 +-
> > scripts/lib/devtool/standard.py | 4 ++--
> > scripts/lib/recipetool/create_buildsys.py | 2 +-
> > scripts/lib/recipetool/create_buildsys_python.py | 6 +++---
> > scripts/oe-pkgdata-util | 2 +-
> > 7 files changed, 12 insertions(+), 12 deletions(-)
> >
> >diff --git a/scripts/bitbake-whatchanged b/scripts/bitbake-whatchanged
> >index a20adb2..b05aead 100755
> >--- a/scripts/bitbake-whatchanged
> >+++ b/scripts/bitbake-whatchanged
> >@@ -120,7 +120,7 @@ def print_added(d_new = None, d_old = None):
> > Print the newly added tasks
> > """
> > added = {}
> >- for k in d_new.keys():
> >+ for k in list(d_new.keys()):
> > if k not in d_old:
> > # Add the new one to added dict, and remove it from
> > # d_new, so the remaining ones are the changed ones
> >@@ -155,7 +155,7 @@ def print_vrchanged(d_new = None, d_old = None, vr = None):
> > """
> > pvchanged = {}
> > counter = 0
> >- for k in d_new.keys():
> >+ for k in list(d_new.keys()):
> > if d_new.get(k).get(vr) != d_old.get(k).get(vr):
> > counter += 1
> > pn, task = split_pntask(k)
> >@@ -279,7 +279,7 @@ Note:
> > # Remove the same one from both stamps.
> > cnt_unchanged = 0
> >- for k in new_dict.keys():
> >+ for k in list(new_dict.keys()):
> > if k in old_dict:
> > cnt_unchanged += 1
> > del(new_dict[k])
> >diff --git a/scripts/combo-layer b/scripts/combo-layer
> >index 234d9e4..7c41f92 100755
> >--- a/scripts/combo-layer
> >+++ b/scripts/combo-layer
> >@@ -1186,7 +1186,7 @@ def update_with_history(conf, components, revisions, repos):
> > msg = conf_commit_msg(conf, components)
> > new_tree = runcmd("git write-tree", **wargs).strip()
> > new_rev = runcmd("git commit-tree".split() +
> >- add_p([head] + additional_heads.keys()) +
> >+ add_p([head] + list(additional_heads.keys())) +
> > ["-m", msg, new_tree],
> > **wargs).strip()
> > # And done! This is the first time we change the HEAD in the actual work tree.
> >diff --git a/scripts/lib/devtool/build.py b/scripts/lib/devtool/build.py
> >index 48f6fe1..6be549d 100644
> >--- a/scripts/lib/devtool/build.py
> >+++ b/scripts/lib/devtool/build.py
> >@@ -27,7 +27,7 @@ logger = logging.getLogger('devtool')
> > def _set_file_values(fn, values):
> >- remaining = values.keys()
> >+ remaining = list(values.keys())
> > def varfunc(varname, origvalue, op, newlines):
> > newvalue = values.get(varname, origvalue)
> >diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py
> >index 08153c6..a2516d6 100644
> >--- a/scripts/lib/devtool/standard.py
> >+++ b/scripts/lib/devtool/standard.py
> >@@ -998,7 +998,7 @@ def _export_local_files(srctree, rd, destdir):
> > bb.process.run(['git', 'checkout', tree, '--', '.'], cwd=srctree,
> > env=dict(os.environ, GIT_WORK_TREE=destdir,
> > GIT_INDEX_FILE=tmp_index))
> >- new_set = _git_ls_tree(srctree, tree, True).keys()
> >+ new_set = list(_git_ls_tree(srctree, tree, True).keys())
> > elif os.path.isdir(local_files_dir):
> > # If not tracked by Git, just copy from working copy
> > new_set = _ls_tree(os.path.join(srctree, 'oe-local-files'))
> >@@ -1309,7 +1309,7 @@ def reset(args, config, basepath, workspace):
> > raise DevtoolError("Recipe must be specified, or specify -a/--all to "
> > "reset all recipes")
> > if args.all:
> >- recipes = workspace.keys()
> >+ recipes = list(workspace.keys())
> > else:
> > recipes = [args.recipename]
> >diff --git a/scripts/lib/recipetool/create_buildsys.py b/scripts/lib/recipetool/create_buildsys.py
> >index de3d9ae..78ae4bc 100644
> >--- a/scripts/lib/recipetool/create_buildsys.py
> >+++ b/scripts/lib/recipetool/create_buildsys.py
> >@@ -682,7 +682,7 @@ class AutotoolsRecipeHandler(RecipeHandler):
> > process_macro(in_keyword, partial)
> > if extravalues:
> >- for k,v in extravalues.items():
> >+ for k,v in list(extravalues.items()):
> > if v:
> > if v.startswith('$') or v.startswith('@') or v.startswith('%'):
> > del extravalues[k]
> >diff --git a/scripts/lib/recipetool/create_buildsys_python.py b/scripts/lib/recipetool/create_buildsys_python.py
> >index 55cce0e..aff13cf 100644
> >--- a/scripts/lib/recipetool/create_buildsys_python.py
> >+++ b/scripts/lib/recipetool/create_buildsys_python.py
> >@@ -361,7 +361,7 @@ class PythonRecipeHandler(RecipeHandler):
> > # Naive mapping of setup() arguments to PKG-INFO field names
> > for d in [info, non_literals]:
> >- for key, value in d.items():
> >+ for key, value in list(d.items()):
> > new_key = _map(key)
> > if new_key != key:
> > del d[key]
> >@@ -443,7 +443,7 @@ class PythonRecipeHandler(RecipeHandler):
> > elif new_value != value:
> > info[variable] = new_value
> > elif hasattr(value, 'items'):
> >- for dkey, dvalue in value.items():
> >+ for dkey, dvalue in list(value.items()):
> > new_list = []
> > for pos, a_value in enumerate(dvalue):
> > new_value = replace_value(search, replace, a_value)
> >@@ -608,7 +608,7 @@ def gather_setup_info(fileobj):
> > visitor.visit(parsed)
> > non_literals, extensions = {}, []
> >- for key, value in visitor.keywords.items():
> >+ for key, value in list(visitor.keywords.items()):
> > if key == 'ext_modules':
> > if isinstance(value, list):
> > for ext in value:
> >diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util
> >index b39d9b5..b16ecc9 100755
> >--- a/scripts/oe-pkgdata-util
> >+++ b/scripts/oe-pkgdata-util
> >@@ -240,7 +240,7 @@ def lookup_pkg(args):
> > sys.exit(1)
> > if args.reverse:
> >- items = mappings.values()
> >+ items = list(mappings.values())
> > else:
> > items = []
> > for pkg in pkgs:
>
--
--
Regards,
Ed
next prev parent reply other threads:[~2016-06-02 15:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-02 10:12 [PATCH 00/16] porting scripts to python3 Ed Bartosh
2016-06-02 10:12 ` [PATCH 01/16] scripts: python3: convert iterables to lists Ed Bartosh
2016-06-02 13:55 ` Leonardo Sandoval
2016-06-02 15:04 ` Ed Bartosh [this message]
2016-06-02 10:12 ` [PATCH 02/16] scripts: python3: use new style except statement Ed Bartosh
2016-06-02 10:12 ` [PATCH 03/16] scripts: python3: rename raw_input to input Ed Bartosh
2016-06-02 10:12 ` [PATCH 04/16] scripts: python3: fix urllib imports Ed Bartosh
2016-06-02 10:12 ` [PATCH 05/16] ksize.py: python3: get rid of strings.join Ed Bartosh
2016-06-02 10:12 ` [PATCH 06/16] scripts: python3: get rid of __future__ imports Ed Bartosh
2016-06-02 10:12 ` [PATCH 07/16] scripts: python3: use new metaclass syntax Ed Bartosh
2016-06-02 10:12 ` [PATCH 08/16] combo-layer: python3: import reduce Ed Bartosh
2016-06-02 10:12 ` [PATCH 09/16] engine.py: python3: rename sys.maxint to sys.maxsize Ed Bartosh
2016-06-02 10:12 ` [PATCH 10/16] scripts: python3: use explicit relative imports Ed Bartosh
2016-06-02 10:12 ` [PATCH 11/16] scripts: python3: replace exec statement with builtin Ed Bartosh
2016-06-02 10:12 ` [PATCH 12/16] engine: python3: replace iteritems() -> items() Ed Bartosh
2016-06-06 17:34 ` Ibarra Lopez, Humberto
2016-06-02 10:12 ` [PATCH 13/16] dirsize: python3: fix TypeError: unorderable types Ed Bartosh
2016-06-02 10:13 ` [PATCH 14/16] scripts: python3: decode subprocess output Ed Bartosh
2016-06-02 10:13 ` [PATCH 15/16] combo-layer: python3: use tempfile.TemporaryFile Ed Bartosh
2016-06-02 10:13 ` [PATCH 16/16] scripts: python3: change python to python3 in shebang Ed Bartosh
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=20160602150430.GA21917@linux.intel.com \
--to=ed.bartosh@linux.intel.com \
--cc=leonardo.sandoval.gonzalez@linux.intel.com \
--cc=openembedded-core@lists.openembedded.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.