Merge pull request #1648 from blueyed/simplify-Argument-__repr__
Simplify Argument.__repr__
This commit is contained in:
		
						commit
						df17f862fa
					
				| 
						 | 
					@ -655,20 +655,17 @@ class Argument:
 | 
				
			||||||
                self._long_opts.append(opt)
 | 
					                self._long_opts.append(opt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __repr__(self):
 | 
					    def __repr__(self):
 | 
				
			||||||
        retval = 'Argument('
 | 
					        args = []
 | 
				
			||||||
        if self._short_opts:
 | 
					        if self._short_opts:
 | 
				
			||||||
            retval += '_short_opts: ' + repr(self._short_opts) + ', '
 | 
					            args += ['_short_opts: ' + repr(self._short_opts)]
 | 
				
			||||||
        if self._long_opts:
 | 
					        if self._long_opts:
 | 
				
			||||||
            retval += '_long_opts: ' + repr(self._long_opts) + ', '
 | 
					            args += ['_long_opts: ' + repr(self._long_opts)]
 | 
				
			||||||
        retval += 'dest: ' + repr(self.dest) + ', '
 | 
					        args += ['dest: ' + repr(self.dest)]
 | 
				
			||||||
        if hasattr(self, 'type'):
 | 
					        if hasattr(self, 'type'):
 | 
				
			||||||
            retval += 'type: ' + repr(self.type) + ', '
 | 
					            args += ['type: ' + repr(self.type)]
 | 
				
			||||||
        if hasattr(self, 'default'):
 | 
					        if hasattr(self, 'default'):
 | 
				
			||||||
            retval += 'default: ' + repr(self.default) + ', '
 | 
					            args += ['default: ' + repr(self.default)]
 | 
				
			||||||
        if retval[-2:] == ', ':  # always long enough to test ("Argument(" )
 | 
					        return 'Argument({0})'.format(', '.join(args))
 | 
				
			||||||
            retval = retval[:-2]
 | 
					 | 
				
			||||||
        retval += ')'
 | 
					 | 
				
			||||||
        return retval
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class OptionGroup:
 | 
					class OptionGroup:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,9 @@ class TestParser:
 | 
				
			||||||
        assert argument.dest == 'test'
 | 
					        assert argument.dest == 'test'
 | 
				
			||||||
        argument = parseopt.Argument('-t', '--test', dest='abc')
 | 
					        argument = parseopt.Argument('-t', '--test', dest='abc')
 | 
				
			||||||
        assert argument.dest == 'abc'
 | 
					        assert argument.dest == 'abc'
 | 
				
			||||||
 | 
					        assert str(argument) == (
 | 
				
			||||||
 | 
					            "Argument(_short_opts: ['-t'], _long_opts: ['--test'], dest: 'abc')"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_argument_type(self):
 | 
					    def test_argument_type(self):
 | 
				
			||||||
        argument = parseopt.Argument('-t', dest='abc', type='int')
 | 
					        argument = parseopt.Argument('-t', dest='abc', type='int')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue