Code simplifications - use enumerate

This commit is contained in:
Thomas Nagy 2016-01-06 14:53:18 +01:00
parent 7541929609
commit d23490287a
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
3 changed files with 8 additions and 10 deletions

View File

@ -622,8 +622,8 @@ class BuildContext(Context.Context):
:type tg: :py:class:`waflib.TaskGen.task_gen`
"""
se = id(tg)
for i in range(len(self.groups)):
for t in self.groups[i]:
for i, tmp in enumerate(self.groups):
for t in tmp:
if id(t) == se:
return i
return None
@ -663,8 +663,8 @@ class BuildContext(Context.Context):
"""
if isinstance(idx, str):
g = self.group_names[idx]
for i in range(len(self.groups)):
if id(g) == id(self.groups[i]):
for i, tmp in enumerate(self.groups):
if id(g) == id(tmp):
self.current_group = i
break
else:

View File

@ -1008,11 +1008,10 @@ def compile_fun_noshell(line):
buf = []
dvars = []
app = buf.append
for x in range(len(extr)):
for x, (var, meth) in enumerate(extr):
params[x] = params[x].strip()
if params[x]:
app("lst.extend(%r)" % params[x].split())
(var, meth) = extr[x]
if var == 'SRC':
if meth: app('lst.append(tsk.inputs%s)' % meth)
else: app("lst.extend([a.path_from(cwdx) for a in tsk.inputs])")

View File

@ -165,8 +165,7 @@ Operator precendence rules required for parsing expressions of the form::
#if 1 && 2 != 0
"""
ops = ['* / %', '+ -', '<< >>', '< <= >= >', '== !=', '& | ^', '&& ||', ',']
for x in range(len(ops)):
syms = ops[x]
for x, syms in enumerate(ops):
for u in syms.split():
prec[u] = x
@ -447,8 +446,8 @@ def reduce_tokens(lst, defs, ban=[]):
del lst[i]
accu = to_add[:]
reduce_tokens(accu, defs, ban+[v])
for x in range(len(accu)):
lst.insert(i, accu[x])
for tmp in accu:
lst.insert(i, tmp)
i += 1
else:
# collect the arguments for the funcall