diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 796d5187..382b998d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,4 +26,4 @@ repos: rev: v3.20.0 hooks: - id: pyupgrade - args: [--py3-only] + args: [--py310-plus] diff --git a/oslo_config/_list_opts.py b/oslo_config/_list_opts.py index 141b52bb..5d163fb0 100644 --- a/oslo_config/_list_opts.py +++ b/oslo_config/_list_opts.py @@ -53,8 +53,8 @@ def list_opts(): help=cfg._SOURCE_DRIVER_OPTION_HELP, ) ) - group_name = 'sample_{}_source'.format(source_name) - group_help = 'Example of using a {} source'.format(source_name) + group_name = f'sample_{source_name}_source' + group_help = f'Example of using a {source_name} source' if source_description: group_help = '{}\n\n{}: {}'.format( group_help, diff --git a/oslo_config/cfg.py b/oslo_config/cfg.py index d2a475cc..0bebfbb1 100644 --- a/oslo_config/cfg.py +++ b/oslo_config/cfg.py @@ -190,7 +190,7 @@ class ConfigFileParseError(Error): self.msg = msg 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): @@ -261,7 +261,7 @@ def _search_dirs(dirs, basename, extension=""): :returns: the path to a matching file or directory, or None """ 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): return path @@ -539,7 +539,7 @@ class Opt: deprecated_for_removal=False, deprecated_reason=None, deprecated_since=None, mutable=False, advanced=False): if name.startswith('_'): - raise ValueError('illegal name {} with prefix _'.format(name)) + raise ValueError(f'illegal name {name} with prefix _') self.name = name if type is None: @@ -664,7 +664,7 @@ class Opt: self._logged_deprecation = True pretty_group = group_name or 'DEFAULT' if self.deprecated_reason: - pretty_reason = ' ({})'.format(self.deprecated_reason) + pretty_reason = f' ({self.deprecated_reason})' else: pretty_reason = '' 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): opt = self._get_opt_info(opt_name, group_name)['opt'] logger.log(lvl, "%-30s = %s", - "{}.{}".format(group_name, opt_name), + f"{group_name}.{opt_name}", _sanitize(opt, getattr(group_attr, opt_name))) logger.log(lvl, "*" * 80) diff --git a/oslo_config/generator.py b/oslo_config/generator.py index f5af92a1..67257f14 100644 --- a/oslo_config/generator.py +++ b/oslo_config/generator.py @@ -284,16 +284,16 @@ class _OptFormatter: else: opt_help = opt.help - help_text = '{}{} ({})'.format(opt_prefix, opt_help, opt_type) + help_text = f'{opt_prefix}{opt_help} ({opt_type})' else: help_text = '(%s)' % opt_type lines = self._format_help(help_text) 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: - lines.append('# Maximum value: {}\n'.format(opt.type.max)) + lines.append(f'# Maximum value: {opt.type.max}\n') if getattr(opt.type, 'choices', None): lines.append('# Possible values:\n') @@ -379,9 +379,9 @@ class _OptFormatter: if default_str: default_str = ' ' + default_str.replace('\n', '\n# ') if self.minimal: - lines.append('{} ={}\n'.format(opt.dest, default_str)) + lines.append(f'{opt.dest} ={default_str}\n') else: - lines.append('#{} ={}\n'.format(opt.dest, default_str)) + lines.append(f'#{opt.dest} ={default_str}\n') self.writelines(lines) @@ -578,7 +578,7 @@ def _output_opts(f, group, group_data): except Exception as err: f.write('# Warning: Failed to format sample for %s\n' % (opt.dest,)) - f.write('# {}\n'.format(err)) + f.write(f'# {err}\n') def _get_groups(conf_ns): diff --git a/oslo_config/sources/_environment.py b/oslo_config/sources/_environment.py index 7caaa43a..341fc981 100644 --- a/oslo_config/sources/_environment.py +++ b/oslo_config/sources/_environment.py @@ -86,7 +86,7 @@ class EnvironmentConfigurationSource(sources.ConfigurationSource): :returns: Th expected environment variable name. """ 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): env_name = self.get_name(group_name, option_name) diff --git a/oslo_config/sphinxconfiggen.py b/oslo_config/sphinxconfiggen.py index 3ff5028f..f0abb765 100644 --- a/oslo_config/sphinxconfiggen.py +++ b/oslo_config/sphinxconfiggen.py @@ -56,7 +56,7 @@ def _get_default_basename(config_file): def _generate_sample(app, config_file, base_name): 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 # in the source directory if it doesn't exist. diff --git a/oslo_config/sphinxext.py b/oslo_config/sphinxext.py index 524486f5..93647964 100644 --- a/oslo_config/sphinxext.py +++ b/oslo_config/sphinxext.py @@ -396,7 +396,7 @@ class ConfigGroup(rst.Directive): result.append(text, source_name) if namespace: - title = '{}: {}'.format(namespace, group_name) + title = f'{namespace}: {group_name}' else: title = group_name diff --git a/oslo_config/tests/test_sources.py b/oslo_config/tests/test_sources.py index 90eeca52..ef9d1d84 100644 --- a/oslo_config/tests/test_sources.py +++ b/oslo_config/tests/test_sources.py @@ -185,7 +185,7 @@ class TestEnvironmentConfigurationSource(base.BaseTestCase): def make_uri(name): - return "https://oslo.config/{}.conf".format(name) + return f"https://oslo.config/{name}.conf" _extra_configs = { @@ -244,13 +244,13 @@ def opts_to_ini(uri, *args, **kwargs): # 'g': group, 'o': option, 't': type, and 'v': value for g in opts.keys(): - result += "[{}]\n".format(g) + result += f"[{g}]\n" for o, (t, v) in opts[g].items(): if t == cfg.MultiStrOpt: for i in v: - result += "{} = {}\n".format(o, i) + result += f"{o} = {i}\n" else: - result += "{} = {}\n".format(o, v) + result += f"{o} = {v}\n" return result diff --git a/oslo_config/types.py b/oslo_config/types.py index b1b831b0..26496ee7 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -171,7 +171,7 @@ class String(ConfigType): def __repr__(self): details = [] 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: details.append("regex=%r" % self.regex.pattern) if details: @@ -326,7 +326,7 @@ class Number(ConfigType): def __repr__(self): props = [] 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: if self.min is not None: props.append('min=%g' % self.min) @@ -567,7 +567,7 @@ class Range(ConfigType): def __call__(self, value): value = str(value) num = "0|-?[1-9][0-9]*" - m = re.match("^({})(?:-({}))?$".format(num, num), value) + m = re.match(f"^({num})(?:-({num}))?$", value) if not m: raise ValueError('Invalid Range: %s' % value) left = int(m.group(1)) @@ -857,7 +857,7 @@ class HostAddress(ConfigType): value = self.hostname(value) except ValueError: raise ValueError( - "{} is not a valid host address".format(value)) + f"{value} is not a valid host address") return value def __repr__(self): @@ -909,7 +909,7 @@ class HostDomain(HostAddress): value = self.hostname(value, regex=self.DOMAIN_REGEX) except ValueError: raise ValueError( - "{} is not a valid host address".format(value)) + f"{value} is not a valid host address") return value def __repr__(self):