Bump pyupgrade target to 3.10+
... according to the versions currently supported. Change-Id: Iec5c4cf3bd2bf2ccd7f9920f69643d4b46976f04 Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
@@ -26,4 +26,4 @@ repos:
|
|||||||
rev: v3.20.0
|
rev: v3.20.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: [--py3-only]
|
args: [--py310-plus]
|
||||||
|
@@ -53,8 +53,8 @@ def list_opts():
|
|||||||
help=cfg._SOURCE_DRIVER_OPTION_HELP,
|
help=cfg._SOURCE_DRIVER_OPTION_HELP,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
group_name = 'sample_{}_source'.format(source_name)
|
group_name = f'sample_{source_name}_source'
|
||||||
group_help = 'Example of using a {} source'.format(source_name)
|
group_help = f'Example of using a {source_name} source'
|
||||||
if source_description:
|
if source_description:
|
||||||
group_help = '{}\n\n{}: {}'.format(
|
group_help = '{}\n\n{}: {}'.format(
|
||||||
group_help,
|
group_help,
|
||||||
|
@@ -190,7 +190,7 @@ class ConfigFileParseError(Error):
|
|||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Failed to parse {}: {}'.format(self.config_file, self.msg)
|
return f'Failed to parse {self.config_file}: {self.msg}'
|
||||||
|
|
||||||
|
|
||||||
class ConfigSourceValueError(Error, ValueError):
|
class ConfigSourceValueError(Error, ValueError):
|
||||||
@@ -261,7 +261,7 @@ def _search_dirs(dirs, basename, extension=""):
|
|||||||
:returns: the path to a matching file or directory, or None
|
:returns: the path to a matching file or directory, or None
|
||||||
"""
|
"""
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
path = os.path.join(d, '{}{}'.format(basename, extension))
|
path = os.path.join(d, f'{basename}{extension}')
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@@ -539,7 +539,7 @@ class Opt:
|
|||||||
deprecated_for_removal=False, deprecated_reason=None,
|
deprecated_for_removal=False, deprecated_reason=None,
|
||||||
deprecated_since=None, mutable=False, advanced=False):
|
deprecated_since=None, mutable=False, advanced=False):
|
||||||
if name.startswith('_'):
|
if name.startswith('_'):
|
||||||
raise ValueError('illegal name {} with prefix _'.format(name))
|
raise ValueError(f'illegal name {name} with prefix _')
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
if type is None:
|
if type is None:
|
||||||
@@ -664,7 +664,7 @@ class Opt:
|
|||||||
self._logged_deprecation = True
|
self._logged_deprecation = True
|
||||||
pretty_group = group_name or 'DEFAULT'
|
pretty_group = group_name or 'DEFAULT'
|
||||||
if self.deprecated_reason:
|
if self.deprecated_reason:
|
||||||
pretty_reason = ' ({})'.format(self.deprecated_reason)
|
pretty_reason = f' ({self.deprecated_reason})'
|
||||||
else:
|
else:
|
||||||
pretty_reason = ''
|
pretty_reason = ''
|
||||||
format_str = ('Option "%(option)s" from group "%(group)s" is '
|
format_str = ('Option "%(option)s" from group "%(group)s" is '
|
||||||
@@ -2822,7 +2822,7 @@ class ConfigOpts(abc.Mapping):
|
|||||||
for opt_name in sorted(self._groups[group_name]._opts):
|
for opt_name in sorted(self._groups[group_name]._opts):
|
||||||
opt = self._get_opt_info(opt_name, group_name)['opt']
|
opt = self._get_opt_info(opt_name, group_name)['opt']
|
||||||
logger.log(lvl, "%-30s = %s",
|
logger.log(lvl, "%-30s = %s",
|
||||||
"{}.{}".format(group_name, opt_name),
|
f"{group_name}.{opt_name}",
|
||||||
_sanitize(opt, getattr(group_attr, opt_name)))
|
_sanitize(opt, getattr(group_attr, opt_name)))
|
||||||
|
|
||||||
logger.log(lvl, "*" * 80)
|
logger.log(lvl, "*" * 80)
|
||||||
|
@@ -284,16 +284,16 @@ class _OptFormatter:
|
|||||||
else:
|
else:
|
||||||
opt_help = opt.help
|
opt_help = opt.help
|
||||||
|
|
||||||
help_text = '{}{} ({})'.format(opt_prefix, opt_help, opt_type)
|
help_text = f'{opt_prefix}{opt_help} ({opt_type})'
|
||||||
else:
|
else:
|
||||||
help_text = '(%s)' % opt_type
|
help_text = '(%s)' % opt_type
|
||||||
lines = self._format_help(help_text)
|
lines = self._format_help(help_text)
|
||||||
|
|
||||||
if getattr(opt.type, 'min', None) is not None:
|
if getattr(opt.type, 'min', None) is not None:
|
||||||
lines.append('# Minimum value: {}\n'.format(opt.type.min))
|
lines.append(f'# Minimum value: {opt.type.min}\n')
|
||||||
|
|
||||||
if getattr(opt.type, 'max', None) is not None:
|
if getattr(opt.type, 'max', None) is not None:
|
||||||
lines.append('# Maximum value: {}\n'.format(opt.type.max))
|
lines.append(f'# Maximum value: {opt.type.max}\n')
|
||||||
|
|
||||||
if getattr(opt.type, 'choices', None):
|
if getattr(opt.type, 'choices', None):
|
||||||
lines.append('# Possible values:\n')
|
lines.append('# Possible values:\n')
|
||||||
@@ -379,9 +379,9 @@ class _OptFormatter:
|
|||||||
if default_str:
|
if default_str:
|
||||||
default_str = ' ' + default_str.replace('\n', '\n# ')
|
default_str = ' ' + default_str.replace('\n', '\n# ')
|
||||||
if self.minimal:
|
if self.minimal:
|
||||||
lines.append('{} ={}\n'.format(opt.dest, default_str))
|
lines.append(f'{opt.dest} ={default_str}\n')
|
||||||
else:
|
else:
|
||||||
lines.append('#{} ={}\n'.format(opt.dest, default_str))
|
lines.append(f'#{opt.dest} ={default_str}\n')
|
||||||
|
|
||||||
self.writelines(lines)
|
self.writelines(lines)
|
||||||
|
|
||||||
@@ -578,7 +578,7 @@ def _output_opts(f, group, group_data):
|
|||||||
except Exception as err:
|
except Exception as err:
|
||||||
f.write('# Warning: Failed to format sample for %s\n' %
|
f.write('# Warning: Failed to format sample for %s\n' %
|
||||||
(opt.dest,))
|
(opt.dest,))
|
||||||
f.write('# {}\n'.format(err))
|
f.write(f'# {err}\n')
|
||||||
|
|
||||||
|
|
||||||
def _get_groups(conf_ns):
|
def _get_groups(conf_ns):
|
||||||
|
@@ -86,7 +86,7 @@ class EnvironmentConfigurationSource(sources.ConfigurationSource):
|
|||||||
:returns: Th expected environment variable name.
|
:returns: Th expected environment variable name.
|
||||||
"""
|
"""
|
||||||
group_name = group_name or 'DEFAULT'
|
group_name = group_name or 'DEFAULT'
|
||||||
return 'OS_{}__{}'.format(group_name.upper(), option_name.upper())
|
return f'OS_{group_name.upper()}__{option_name.upper()}'
|
||||||
|
|
||||||
def get(self, group_name, option_name, opt):
|
def get(self, group_name, option_name, opt):
|
||||||
env_name = self.get_name(group_name, option_name)
|
env_name = self.get_name(group_name, option_name)
|
||||||
|
@@ -56,7 +56,7 @@ def _get_default_basename(config_file):
|
|||||||
def _generate_sample(app, config_file, base_name):
|
def _generate_sample(app, config_file, base_name):
|
||||||
|
|
||||||
def info(msg):
|
def info(msg):
|
||||||
LOG.info('[{}] {}'.format(__name__, msg))
|
LOG.info(f'[{__name__}] {msg}')
|
||||||
|
|
||||||
# If we are given a file that isn't an absolute path, look for it
|
# If we are given a file that isn't an absolute path, look for it
|
||||||
# in the source directory if it doesn't exist.
|
# in the source directory if it doesn't exist.
|
||||||
|
@@ -396,7 +396,7 @@ class ConfigGroup(rst.Directive):
|
|||||||
result.append(text, source_name)
|
result.append(text, source_name)
|
||||||
|
|
||||||
if namespace:
|
if namespace:
|
||||||
title = '{}: {}'.format(namespace, group_name)
|
title = f'{namespace}: {group_name}'
|
||||||
else:
|
else:
|
||||||
title = group_name
|
title = group_name
|
||||||
|
|
||||||
|
@@ -185,7 +185,7 @@ class TestEnvironmentConfigurationSource(base.BaseTestCase):
|
|||||||
|
|
||||||
|
|
||||||
def make_uri(name):
|
def make_uri(name):
|
||||||
return "https://oslo.config/{}.conf".format(name)
|
return f"https://oslo.config/{name}.conf"
|
||||||
|
|
||||||
|
|
||||||
_extra_configs = {
|
_extra_configs = {
|
||||||
@@ -244,13 +244,13 @@ def opts_to_ini(uri, *args, **kwargs):
|
|||||||
|
|
||||||
# 'g': group, 'o': option, 't': type, and 'v': value
|
# 'g': group, 'o': option, 't': type, and 'v': value
|
||||||
for g in opts.keys():
|
for g in opts.keys():
|
||||||
result += "[{}]\n".format(g)
|
result += f"[{g}]\n"
|
||||||
for o, (t, v) in opts[g].items():
|
for o, (t, v) in opts[g].items():
|
||||||
if t == cfg.MultiStrOpt:
|
if t == cfg.MultiStrOpt:
|
||||||
for i in v:
|
for i in v:
|
||||||
result += "{} = {}\n".format(o, i)
|
result += f"{o} = {i}\n"
|
||||||
else:
|
else:
|
||||||
result += "{} = {}\n".format(o, v)
|
result += f"{o} = {v}\n"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@@ -171,7 +171,7 @@ class String(ConfigType):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
details = []
|
details = []
|
||||||
if self.choices is not None:
|
if self.choices is not None:
|
||||||
details.append("choices={!r}".format(list(self.choices.keys())))
|
details.append(f"choices={list(self.choices.keys())!r}")
|
||||||
if self.regex:
|
if self.regex:
|
||||||
details.append("regex=%r" % self.regex.pattern)
|
details.append("regex=%r" % self.regex.pattern)
|
||||||
if details:
|
if details:
|
||||||
@@ -326,7 +326,7 @@ class Number(ConfigType):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
props = []
|
props = []
|
||||||
if self.choices is not None:
|
if self.choices is not None:
|
||||||
props.append("choices={!r}".format(list(self.choices.keys())))
|
props.append(f"choices={list(self.choices.keys())!r}")
|
||||||
else:
|
else:
|
||||||
if self.min is not None:
|
if self.min is not None:
|
||||||
props.append('min=%g' % self.min)
|
props.append('min=%g' % self.min)
|
||||||
@@ -567,7 +567,7 @@ class Range(ConfigType):
|
|||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
value = str(value)
|
value = str(value)
|
||||||
num = "0|-?[1-9][0-9]*"
|
num = "0|-?[1-9][0-9]*"
|
||||||
m = re.match("^({})(?:-({}))?$".format(num, num), value)
|
m = re.match(f"^({num})(?:-({num}))?$", value)
|
||||||
if not m:
|
if not m:
|
||||||
raise ValueError('Invalid Range: %s' % value)
|
raise ValueError('Invalid Range: %s' % value)
|
||||||
left = int(m.group(1))
|
left = int(m.group(1))
|
||||||
@@ -857,7 +857,7 @@ class HostAddress(ConfigType):
|
|||||||
value = self.hostname(value)
|
value = self.hostname(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"{} is not a valid host address".format(value))
|
f"{value} is not a valid host address")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -909,7 +909,7 @@ class HostDomain(HostAddress):
|
|||||||
value = self.hostname(value, regex=self.DOMAIN_REGEX)
|
value = self.hostname(value, regex=self.DOMAIN_REGEX)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"{} is not a valid host address".format(value))
|
f"{value} is not a valid host address")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
Reference in New Issue
Block a user