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
This commit is contained in:
Mike Frysinger 2019-06-13 02:13:23 -04:00
parent 35159abbeb
commit 31067c0ac5
3 changed files with 8 additions and 8 deletions

View File

@ -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.

View File

@ -58,7 +58,7 @@ It is equivalent to "git branch -D <branchname>".
pm.update()
if opt.all:
branches = project.GetBranches().keys()
branches = list(project.GetBranches().keys())
else:
branches = [nb]

View File

@ -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: