Skip to content
Snippets Groups Projects
Commit 3895b88a authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[pre-commit] Use pyupgrade, update code to conform to python>=3.8

parent 90133062
Branches
Tags
No related merge requests found
Pipeline #65873 passed
......@@ -23,6 +23,11 @@ repos:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports]
exclude: '^.*/data/second_config\.py$'
- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.3.0"
hooks:
......
......@@ -709,11 +709,11 @@ def config_group(
}
# all modules with configuration resources
modules: set[str] = set(
modules: set[str] = {
# note: k.module does not exist on Python < 3.9
k.value.split(":")[0].rsplit(".", 1)[0]
for k in entry_points.values()
)
}
keep_modules: set[str] = set()
for k in sorted(modules):
if k not in keep_modules and not any(
......@@ -744,7 +744,7 @@ def config_group(
# 79 - 4 spaces = 75 (see string above)
description_leftover = 75 - longest_name_length
click.echo("module: %s" % (config_type,))
click.echo(f"module: {config_type}")
for name in sorted(entry_points_by_module[config_type]):
ep = entry_points[name]
......@@ -824,7 +824,7 @@ def config_group(
):
fname = inspect.getfile(mod)
click.echo("Contents:")
with open(fname, "r") as f:
with open(fname) as f:
click.echo(f.read())
else: # only output documentation, if module
doc = inspect.getdoc(mod)
......@@ -862,7 +862,7 @@ def config_group(
ep = entry_points[source]
mod = ep.load()
src_name = inspect.getfile(mod)
logger.info("cp %s -> %s" % (src_name, destination))
logger.info(f"cp {src_name} -> {destination}")
shutil.copyfile(src_name, destination)
return group_wrapper
......
# vim: set fileencoding=utf-8 :
"""Functionality to implement python-based config file parsing and loading."""
from __future__ import annotations
......@@ -88,7 +86,7 @@ def _get_module_filename(module_name: str) -> str | None:
def _object_name(
path: typing.Union[str, pathlib.Path], common_name: str | None
path: str | pathlib.Path, common_name: str | None
) -> tuple[str, str | None]:
if isinstance(path, pathlib.Path):
......@@ -119,7 +117,7 @@ def _retrieve_entry_points(group: str) -> typing.Iterable[EntryPoint]:
def _resolve_entry_point_or_modules(
paths: list[typing.Union[str, pathlib.Path]],
paths: list[str | pathlib.Path],
entry_point_group: str | None = None,
common_name: str | None = None,
) -> tuple[list[str], list[str], list[str]]:
......@@ -217,11 +215,11 @@ def _resolve_entry_point_or_modules(
def load(
paths: list[typing.Union[str, pathlib.Path]],
paths: list[str | pathlib.Path],
context: dict[str, typing.Any] | None = None,
entry_point_group: str | None = None,
attribute_name: str | None = None,
) -> typing.Union[types.ModuleType, typing.Any]:
) -> types.ModuleType | typing.Any:
"""Loads a set of configuration files, in sequence.
This method will load one or more configuration files. Every time a
......
# vim: set fileencoding=utf-8 :
"""Implements a global configuration system setup and readout."""
from __future__ import annotations
......@@ -53,7 +51,7 @@ class UserDefaults(collections.abc.MutableMapping):
def __init__(
self,
path: typing.Union[str, pathlib.Path],
path: str | pathlib.Path,
envname: str | None = None,
logger: logging.Logger | None = None,
) -> None:
......
......@@ -59,7 +59,7 @@ def test_commands_with_config_2():
@click.option("-a", type=click.INT, cls=ResourceOption)
def cli(a, **_):
assert type(a) == int, (type(a), a)
click.echo("{}".format(a))
click.echo(f"{a}")
runner = CliRunner()
......@@ -85,7 +85,7 @@ def test_commands_with_config_3():
@click.command(cls=ConfigCommand, entry_point_group="exposed.test.config")
@click.option("-a", cls=ResourceOption, required=True)
def cli(a, **_):
click.echo("{}".format(a))
click.echo(f"{a}")
runner = CliRunner()
......@@ -110,7 +110,7 @@ def test_commands_with_config_3():
def _assert_config_dump(output, ref, ref_date):
with output.open("rt") as f, open(ref, "rt") as f2:
with output.open("rt") as f, open(ref) as f2:
diff = difflib.ndiff(f.readlines(), f2.readlines())
important_diffs = [k for k in diff if k.startswith(("+", "-"))]
......
......@@ -175,7 +175,7 @@ def test_rc_str(tmp_path):
rc["section1.an_int"] = 15
rc.write()
assert open(tmp_path / "new-rc", "rt").read() == str(rc)
assert open(tmp_path / "new-rc").read() == str(rc)
def test_rc_json_legacy(datadir, tmp_path):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment