Skip to content

Commit 474f566

Browse files
committed
Use enumerate instead of range(len()), indent code
1 parent bffa6e0 commit 474f566

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

pygccxml/declarations/matchers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,11 @@ def __str__(self):
449449
if self.return_type is not None:
450450
msg.append('(return type==%s)' % str(self.return_type))
451451
if self.arg_types:
452-
for i in range(len(self.arg_types)):
453-
if self.arg_types[i] is None:
452+
for i, arg_type in enumerate(self.arg_types):
453+
if arg_type is None:
454454
msg.append('(arg %d type==any)' % i)
455455
else:
456-
msg.append(
457-
'(arg %d type==%s)' %
458-
(i, str(self.arg_types[i])))
456+
msg.append('(arg %d type==%s)' % (i, str(arg_type)))
459457
if not msg:
460458
msg.append('any')
461459
return ' and '.join(msg)

pygccxml/parser/linker.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ def __link_calldef(self):
8787
else:
8888
for arg in self.__inst.arguments:
8989
arg.type = self.__link_type(arg.type)
90-
for index in range(len(self.__inst.exceptions)):
90+
for i, exception in enumerate(self.__inst.exceptions):
9191
try:
92-
self.__inst.exceptions[index] = self.__decls[
93-
self.__inst.exceptions[index]]
92+
self.__inst.exceptions[i] = self.__decls[exception]
9493
except KeyError:
95-
self.__inst.exceptions[index] = self.__link_type(
96-
self.__inst.exceptions[index])
94+
self.__inst.exceptions[i] = self.__link_type(exception)
9795

9896
def visit_member_function(self):
9997
self.__link_calldef()

unittests/parser_test_case.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,15 @@ def _test_calldef_args(self, calldef, expected_args):
4747
len(calldef.arguments) == len(expected_args),
4848
("the function's '%s' expected number of arguments is '%d' and " +
4949
"in reality it is different('%d')") %
50-
(calldef.name,
51-
len(expected_args),
52-
len(calldef.arguments)))
53-
for ordinal in range(len(expected_args)):
54-
arg = calldef.arguments[ordinal]
55-
expected_arg = expected_args[ordinal]
50+
(calldef.name, len(expected_args), len(calldef.arguments)))
51+
52+
for i, expected_arg in enumerate(expected_args):
53+
arg = calldef.arguments[i]
5654
self.failUnless(
5755
arg == expected_arg,
5856
("the function's '%s' expected %d's argument is '%s' and in " +
5957
"reality it is different('%s')") %
60-
(calldef.name,
61-
ordinal, pprint.pformat(expected_arg.__dict__),
58+
(calldef.name, i, pprint.pformat(expected_arg.__dict__),
6259
pprint.pformat(arg.__dict__)))
6360

6461
def _test_calldef_exceptions(self, calldef, exceptions):

0 commit comments

Comments
 (0)