Skip to content

Commit df17f86

Browse files
authored
Merge pull request #1648 from blueyed/simplify-Argument-__repr__
Simplify Argument.__repr__
2 parents 7eb1318 + 939407e commit df17f86

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-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:

testing/test_parseopt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def test_argument(self):
2929
assert argument.dest == 'test'
3030
argument = parseopt.Argument('-t', '--test', dest='abc')
3131
assert argument.dest == 'abc'
32+
assert str(argument) == (
33+
"Argument(_short_opts: ['-t'], _long_opts: ['--test'], dest: 'abc')"
34+
)
3235

3336
def test_argument_type(self):
3437
argument = parseopt.Argument('-t', dest='abc', type='int')

0 commit comments

Comments
 (0)