From 31067c0ac583af2304ffe52c11df8b14c6162502 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 13 Jun 2019 02:13:23 -0400 Subject: [PATCH] tweak raise/dict syntax for Python 3 compat Use the `raise` statement directly. Switch to using .items() instead of .iteritems(). Python 3 doesn't have .iteritems() as .items() is a generator, and these are small enough that the Python 2 overhead should be negligible. We have to run .keys() through list() in a few places as Python 3 uses a generator and we sometimes want to iterate more than once. That's why we don't change all .keys() or .items() calls -- most are in places where generators are fine. Bug: https://crbug.com/gerrit/10418 Change-Id: I469899d9b77ffd77ccabb831bc4b217407fefe6f --- gitc_utils.py | 12 ++++++------ subcmds/abandon.py | 2 +- subcmds/info.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gitc_utils.py b/gitc_utils.py index 0d4a5c38..f49f7be6 100644 --- a/gitc_utils.py +++ b/gitc_utils.py @@ -58,8 +58,8 @@ def _set_project_revisions(projects): sys.exit(1) revisionExpr = gitcmd.stdout.split('\t')[0] if not revisionExpr: - raise(ManifestParseError('Invalid SHA-1 revision project %s (%s)' % - (proj.remote.url, proj.revisionExpr))) + raise ManifestParseError('Invalid SHA-1 revision project %s (%s)' % + (proj.remote.url, proj.revisionExpr)) proj.revisionExpr = revisionExpr def _manifest_groups(manifest): @@ -87,7 +87,7 @@ def generate_gitc_manifest(gitc_manifest, manifest, paths=None): print('Generating GITC Manifest by fetching revision SHAs for each ' 'project.') if paths is None: - paths = manifest.paths.keys() + paths = list(manifest.paths.keys()) groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x] @@ -96,7 +96,7 @@ def generate_gitc_manifest(gitc_manifest, manifest, paths=None): projects = [p for p in projects if p.MatchesGroups(groups)] if gitc_manifest is not None: - for path, proj in manifest.paths.iteritems(): + for path, proj in manifest.paths.items(): if not proj.MatchesGroups(groups): continue @@ -124,7 +124,7 @@ def generate_gitc_manifest(gitc_manifest, manifest, paths=None): index += NUM_BATCH_RETRIEVE_REVISIONID if gitc_manifest is not None: - for path, proj in gitc_manifest.paths.iteritems(): + for path, proj in gitc_manifest.paths.items(): if proj.old_revision and path in paths: # If we updated a project that has been started, keep the old-revision # updated. @@ -133,7 +133,7 @@ def generate_gitc_manifest(gitc_manifest, manifest, paths=None): repo_proj.revisionExpr = None # Convert URLs from relative to absolute. - for _name, remote in manifest.remotes.iteritems(): + for _name, remote in manifest.remotes.items(): remote.fetchUrl = remote.resolvedFetchUrl # Save the manifest. diff --git a/subcmds/abandon.py b/subcmds/abandon.py index be32dc5c..f1c2a839 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py @@ -58,7 +58,7 @@ It is equivalent to "git branch -D ". pm.update() if opt.all: - branches = project.GetBranches().keys() + branches = list(project.GetBranches().keys()) else: branches = [nb] diff --git a/subcmds/info.py b/subcmds/info.py index f2827b34..2fff3acc 100644 --- a/subcmds/info.py +++ b/subcmds/info.py @@ -99,7 +99,7 @@ class Info(PagedCommand): self.headtext(p.revisionExpr) self.out.nl() - localBranches = p.GetBranches().keys() + localBranches = list(p.GetBranches().keys()) self.heading("Local Branches: ") self.redtext(str(len(localBranches))) if len(localBranches) > 0: