diff options
author | Hugo <hugovk@users.noreply.github.com> | 2018-10-13 14:42:56 +0300 |
---|---|---|
committer | Jürgen Hermann <jh@web.de> | 2018-10-13 17:09:24 +0200 |
commit | 5e25a9a32d49f647aeb9a69e5bbfa798040c45a0 (patch) | |
tree | 5b3c98cbb0b936b0febdcd459c808a4c7a105c0b | |
parent | 8eeaefcb5d8cf349fc228faa0ed9c036ae302fcd (diff) | |
download | configobj-git-5e25a9a32d49f647aeb9a69e5bbfa798040c45a0.tar.gz |
Upgrade Python syntax with pyupgrade https://github.com/asottile/pyupgrade
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | src/configobj/__init__.py | 20 | ||||
-rw-r--r-- | src/configobj/validate.py | 20 | ||||
-rw-r--r-- | src/tests/configobj_doctests.py | 2 | ||||
-rw-r--r-- | src/tests/test_validate.py | 2 |
5 files changed, 23 insertions, 23 deletions
@@ -80,7 +80,7 @@ try: LONG_DESCRIPTION += handle.read() except EnvironmentError as exc: # Build / install anyway - print("WARNING: Cannot open/read CHANGES.rst due to {0}".format(exc)) + print("WARNING: Cannot open/read CHANGES.rst due to {}".format(exc)) CLASSIFIERS = [ # Details at http://pypi.python.org/pypi?:action=list_classifiers diff --git a/src/configobj/__init__.py b/src/configobj/__init__.py index 3f6eac0..ac963d7 100644 --- a/src/configobj/__init__.py +++ b/src/configobj/__init__.py @@ -693,7 +693,7 @@ class Section(dict): return self[key] except MissingInterpolationOption: return dict.__getitem__(self, key) - return '{%s}' % ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) + return '{%s}' % ', '.join([('{}: {}'.format(repr(key), repr(_getval(key)))) for key in (self.scalars + self.sections)]) __str__ = __repr__ @@ -1026,7 +1026,7 @@ class Section(dict): def _get_triple_quote(value): """Helper for triple-quoting round-trips.""" if ('"""' in value) and ("'''" in value): - raise ConfigObjError('Value cannot be safely quoted: {0!r}'.format(value)) + raise ConfigObjError('Value cannot be safely quoted: {!r}'.format(value)) return tsquot if "'''" in value else tdquot @@ -1275,11 +1275,11 @@ class ConfigObj(Section): # if we had any errors, now is the time to raise them if self._errors: if len(self._errors) > 1: - msg = ["Parsing failed with {0} errors.".format(len(self._errors))] + msg = ["Parsing failed with {} errors.".format(len(self._errors))] for error in self._errors[:self.MAX_PARSE_ERROR_DETAILS]: msg.append(str(error)) if len(self._errors) > self.MAX_PARSE_ERROR_DETAILS: - msg.append("{0} more error(s)!" + msg.append("{} more error(s)!" .format(len(self._errors) - self.MAX_PARSE_ERROR_DETAILS)) error = ConfigObjError('\n '.join(msg)) else: @@ -1337,8 +1337,8 @@ class ConfigObj(Section): return self[key] except MissingInterpolationOption: return dict.__getitem__(self, key) - return ('%s({%s})' % (self.__class__.__name__, - ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) + return ('{}({{{}}})'.format(self.__class__.__name__, + ', '.join([('{}: {}'.format(repr(key), repr(_getval(key)))) for key in (self.scalars + self.sections)]))) @@ -1601,7 +1601,7 @@ class ConfigObj(Section): mat = self._keyword.match(line) if mat is None: self._handle_error( - 'Invalid line ({0!r}) (matched as neither section nor keyword)'.format(line), + 'Invalid line ({!r}) (matched as neither section nor keyword)'.format(line), ParseError, infile, cur_index) else: # is a keyword value @@ -1707,7 +1707,7 @@ class ConfigObj(Section): """ line = infile[cur_index] cur_index += 1 - message = '{0} at line {1}.'.format(text, cur_index) + message = '{} at line {}.'.format(text, cur_index) error = ErrorClass(message, cur_index, line) if self.raise_errors: # raise the error - parsing stops here @@ -1781,7 +1781,7 @@ class ConfigObj(Section): # for normal values either single or double quotes will do elif '\n' in value: # will only happen if multiline is off - e.g. '\n' in key - raise ConfigObjError('Value cannot be safely quoted: {0!r}'.format(value)) + raise ConfigObjError('Value cannot be safely quoted: {!r}'.format(value)) elif ((value[0] not in wspace_plus) and (value[-1] not in wspace_plus) and (',' not in value)): @@ -1800,7 +1800,7 @@ class ConfigObj(Section): def _get_single_quote(self, value): if ("'" in value) and ('"' in value): - raise ConfigObjError('Value cannot be safely quoted: {0!r}'.format(value)) + raise ConfigObjError('Value cannot be safely quoted: {!r}'.format(value)) elif '"' in value: quot = squot else: diff --git a/src/configobj/validate.py b/src/configobj/validate.py index 4660d94..0cc2293 100644 --- a/src/configobj/validate.py +++ b/src/configobj/validate.py @@ -372,7 +372,7 @@ class VdtUnknownCheckError(ValidateError): Traceback (most recent call last): VdtUnknownCheckError: the check "yoda" is unknown. """ - ValidateError.__init__(self, 'the check "%s" is unknown.' % (value,)) + ValidateError.__init__(self, 'the check "{}" is unknown.'.format(value)) class VdtParamError(SyntaxError): @@ -392,7 +392,7 @@ class VdtParamError(SyntaxError): if value is self.NOT_GIVEN: SyntaxError.__init__(self, name_or_msg) else: - SyntaxError.__init__(self, 'passed an incorrect value "%s" for parameter "%s".' % (value, name_or_msg)) + SyntaxError.__init__(self, 'passed an incorrect value "{}" for parameter "{}".'.format(value, name_or_msg)) class VdtTypeError(ValidateError): @@ -404,7 +404,7 @@ class VdtTypeError(ValidateError): Traceback (most recent call last): VdtTypeError: the value "jedi" is of the wrong type. """ - ValidateError.__init__(self, 'the value "%s" is of the wrong type.' % (value,)) + ValidateError.__init__(self, 'the value "{}" is of the wrong type.'.format(value)) class VdtValueError(ValidateError): @@ -416,7 +416,7 @@ class VdtValueError(ValidateError): Traceback (most recent call last): VdtValueError: the value "jedi" is unacceptable. """ - ValidateError.__init__(self, 'the value "%s" is unacceptable.' % (value,)) + ValidateError.__init__(self, 'the value "{}" is unacceptable.'.format(value)) class VdtValueTooSmallError(VdtValueError): @@ -428,7 +428,7 @@ class VdtValueTooSmallError(VdtValueError): Traceback (most recent call last): VdtValueTooSmallError: the value "0" is too small. """ - ValidateError.__init__(self, 'the value "%s" is too small.' % (value,)) + ValidateError.__init__(self, 'the value "{}" is too small.'.format(value)) class VdtValueTooBigError(VdtValueError): @@ -440,7 +440,7 @@ class VdtValueTooBigError(VdtValueError): Traceback (most recent call last): VdtValueTooBigError: the value "1" is too big. """ - ValidateError.__init__(self, 'the value "%s" is too big.' % (value,)) + ValidateError.__init__(self, 'the value "{}" is too big.'.format(value)) class VdtValueTooShortError(VdtValueError): @@ -454,7 +454,7 @@ class VdtValueTooShortError(VdtValueError): """ ValidateError.__init__( self, - 'the value "%s" is too short.' % (value,)) + 'the value "{}" is too short.'.format(value)) class VdtValueTooLongError(VdtValueError): @@ -466,7 +466,7 @@ class VdtValueTooLongError(VdtValueError): Traceback (most recent call last): VdtValueTooLongError: the value "jedie" is too long. """ - ValidateError.__init__(self, 'the value "%s" is too long.' % (value,)) + ValidateError.__init__(self, 'the value "{}" is too long.'.format(value)) class Validator(object): @@ -644,7 +644,7 @@ class Validator(object): fun_kwargs = dict(fun_kwargs) else: fun_name, fun_args, fun_kwargs, default = self._parse_check(check) - fun_kwargs = dict([(str(key), value) for (key, value) in list(fun_kwargs.items())]) + fun_kwargs = {str(key): value for (key, value) in list(fun_kwargs.items())} self._cache[check] = fun_name, list(fun_args), dict(fun_kwargs), default return fun_name, fun_args, fun_kwargs, default @@ -1480,6 +1480,6 @@ if __name__ == '__main__': failures, tests = doctest.testmod( m, globs=globs, optionflags=doctest.IGNORE_EXCEPTION_DETAIL | doctest.ELLIPSIS) - print('{0} {1} failures out of {2} tests' + print('{} {} failures out of {} tests' .format("FAIL" if failures else "*OK*", failures, tests)) sys.exit(bool(failures)) diff --git a/src/tests/configobj_doctests.py b/src/tests/configobj_doctests.py index 95192fc..72aa9b0 100644 --- a/src/tests/configobj_doctests.py +++ b/src/tests/configobj_doctests.py @@ -981,7 +981,7 @@ if __name__ == '__main__': post_failures, post_tests = doctest.testmod( configobj, globs=globs, optionflags=doctest.IGNORE_EXCEPTION_DETAIL | doctest.ELLIPSIS) - print('{0} {1} failures out of {2} tests' + print('{} {} failures out of {} tests' .format("FAIL" if post_failures or pre_failures else "*OK*", post_failures + pre_failures, post_tests + pre_tests)) sys.exit(bool(post_failures or pre_failures)) diff --git a/src/tests/test_validate.py b/src/tests/test_validate.py index 473de71..b775364 100644 --- a/src/tests/test_validate.py +++ b/src/tests/test_validate.py @@ -207,7 +207,7 @@ class TestListChecks(object): mixed = 1, 2, yes, 3.1415 '''.splitlines() configspec = ''' - mixed = mixed_list({0}) + mixed = mixed_list({}) '''.format(typespec).splitlines() configobj = ConfigObj(config, configspec=configspec) assert configobj.validate(val, preserve_errors=True) is True, "Validation failed unexpectedly" |