Skip to content

Commit b3c4ecc

Browse files
committed
Simplify Argument.__repr__
I have came across this when noticing that universal-ctags fails to parse this correctly (universal-ctags/ctags#997).
1 parent 6359e75 commit b3c4ecc

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

_pytest/config.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,20 +655,17 @@ def _set_opt_strings(self, opts):
655655
self._long_opts.append(opt)
656656

657657
def __repr__(self):
658-
retval = 'Argument('
658+
args = []
659659
if self._short_opts:
660-
retval += '_short_opts: ' + repr(self._short_opts) + ', '
660+
args += ['_short_opts: ' + repr(self._short_opts) + ', ']
661661
if self._long_opts:
662-
retval += '_long_opts: ' + repr(self._long_opts) + ', '
663-
retval += 'dest: ' + repr(self.dest) + ', '
662+
args += ['_long_opts: ' + repr(self._long_opts) + ', ']
663+
args += ['dest: ' + repr(self.dest) + ', ']
664664
if hasattr(self, 'type'):
665-
retval += 'type: ' + repr(self.type) + ', '
665+
args += ['type: ' + repr(self.type) + ', ']
666666
if hasattr(self, 'default'):
667-
retval += 'default: ' + repr(self.default) + ', '
668-
if retval[-2:] == ', ': # always long enough to test ("Argument(" )
669-
retval = retval[:-2]
670-
retval += ')'
671-
return retval
667+
args += ['default: ' + repr(self.default) + ', ']
668+
return 'Argument({0})'.format(', '.join(args))
672669

673670

674671
class OptionGroup:

0 commit comments

Comments
 (0)