From ba3b2ccaa99bf11538340a32ae79805b09804ee1 Mon Sep 17 00:00:00 2001 From: Charles de Beauchesne Date: Thu, 9 Jan 2025 15:43:55 +0100 Subject: [PATCH] Activate ANN002, ANN206, PTH102, PTH119 (#3788) --- pyproject.toml | 7 +------ utils/_context/virtual_machines.py | 3 ++- utils/_decorators.py | 2 +- utils/cgroup_info.py | 3 +-- utils/onboarding/injection_log_parser.py | 4 ++-- utils/parametric/spec/tracecontext.py | 2 +- utils/proxy/core.py | 2 +- utils/scripts/markdown_logs.py | 2 +- utils/tools.py | 2 +- 9 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5a5f19856e..b23181790d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,12 +80,10 @@ ignore = [ ### TODO : remove those ignores # missing-type-annotation, the ONE to remove !! "ANN001", - "ANN002", "ANN003", "ANN201", "ANN202", "ANN205", - "ANN206", "BLE001", # Do not catch blind exception: `Exception`, big project to enable this "C901", # code complexity, TBD "E722", # bare except, big project to enable this @@ -97,14 +95,12 @@ ignore = [ "PLR1714", "PLR2004", "PTH100", - "PTH102", "PTH110", "PTH113", "PTH116", "PTH118", - "PTH119", "PTH120", - "PTH122", + "PTH122", # os.path.splitext(), but not really easier to read ? "PTH123", # `open()` should be replaced by `Path.open()` "RUF012", "S202", @@ -248,7 +244,6 @@ ignore = [ "EM102", "PLR0912", "PLR0915", - "PLR1714", "PLW1510", "PTH112", "PTH113", diff --git a/utils/_context/virtual_machines.py b/utils/_context/virtual_machines.py index d7af0bf642..d0d1c72c6f 100644 --- a/utils/_context/virtual_machines.py +++ b/utils/_context/virtual_machines.py @@ -1,6 +1,7 @@ import os import json import hashlib +from pathlib import Path from utils.tools import logger from utils import context @@ -178,7 +179,7 @@ def _load_ip_from_logs(self): def get_log_folder(self): vm_folder = f"{context.scenario.host_log_folder}/{self.name}" if not os.path.exists(vm_folder): - os.mkdir(vm_folder) + Path.mkdir(vm_folder) return vm_folder def get_default_log_file(self): diff --git a/utils/_decorators.py b/utils/_decorators.py index 32f59d16b5..882438a2ff 100644 --- a/utils/_decorators.py +++ b/utils/_decorators.py @@ -30,7 +30,7 @@ class _DecoratorType(enum.StrEnum): # So we use a custom one, based on NPM spec, allowing pre-release versions class CustomParser(semver.NpmSpec.Parser): @classmethod - def range(cls, operator, target): + def range(cls, operator, target) -> semver.base.Range: return semver.base.Range(operator, target, prerelease_policy=semver.base.Range.PRERELEASE_ALWAYS) diff --git a/utils/cgroup_info.py b/utils/cgroup_info.py index aeedb6628d..0966dc3a4a 100644 --- a/utils/cgroup_info.py +++ b/utils/cgroup_info.py @@ -41,8 +41,7 @@ class _CGroupInfo: CONTAINER_RE = re.compile(rf"(?:.+)?({UUID_SOURCE_PATTERN}|{CONTAINER_SOURCE_PATTERN}|{TASK_PATTERN})(?:\.scope)?$") @classmethod - def from_line(cls, line): - # type: (str) -> Optional[_CGroupInfo] + def from_line(cls, line: str) -> "_CGroupInfo | None": """Parse a new :class:`CGroupInfo` from the provided line :param line: A line from a cgroup file (e.g. /proc/self/cgroup) to parse information from :type line: str diff --git a/utils/onboarding/injection_log_parser.py b/utils/onboarding/injection_log_parser.py index 32781f4e59..1f22c4c491 100644 --- a/utils/onboarding/injection_log_parser.py +++ b/utils/onboarding/injection_log_parser.py @@ -1,5 +1,5 @@ import json -import os +from pathlib import Path from utils.tools import logger @@ -58,7 +58,7 @@ def _parse_command(command): if "=" in com: command_args.remove(com) continue - return os.path.basename(com), command_args + return Path(com).name, command_args return None, None diff --git a/utils/parametric/spec/tracecontext.py b/utils/parametric/spec/tracecontext.py index 2b54c67d00..94f6b9d516 100644 --- a/utils/parametric/spec/tracecontext.py +++ b/utils/parametric/spec/tracecontext.py @@ -83,7 +83,7 @@ class Tracestate: _VALUE_VALIDATION_RE = re.compile("^(" + _VALUE_FORMAT + ")$") _MEMBER_FORMAT_RE = re.compile(f"^({_KEY_FORMAT})(=)({_VALUE_FORMAT})$") - def __init__(self, *args, **kwds): + def __init__(self, *args, **kwds): # noqa: ANN002 if len(args) == 1 and not kwds: if isinstance(args[0], str): self._traits: OrderedDict = OrderedDict() diff --git a/utils/proxy/core.py b/utils/proxy/core.py index 58107013d7..4e9f4dc312 100644 --- a/utils/proxy/core.py +++ b/utils/proxy/core.py @@ -23,7 +23,7 @@ class CustomFormatter(logging.Formatter): - def __init__(self, keys: list[str], *args, **kwargs) -> None: + def __init__(self, keys: list[str], *args, **kwargs) -> None: # noqa: ANN002 super().__init__(*args, **kwargs) self._keys = keys diff --git a/utils/scripts/markdown_logs.py b/utils/scripts/markdown_logs.py index 7352d5324c..8dbe3152cc 100644 --- a/utils/scripts/markdown_logs.py +++ b/utils/scripts/markdown_logs.py @@ -3,7 +3,7 @@ import collections -def table_row(*args): +def table_row(*args: list[str]): print(f"| {' | '.join(args)} |") diff --git a/utils/tools.py b/utils/tools.py index 195f5f3242..1c4c893014 100644 --- a/utils/tools.py +++ b/utils/tools.py @@ -52,7 +52,7 @@ def update_environ_with_local_env(): logging.addLevelName(DEBUG_LEVEL_STDOUT, "STDOUT") -def stdout(self, message, *args, **kws): +def stdout(self, message, *args, **kws): # noqa: ANN002 if self.isEnabledFor(DEBUG_LEVEL_STDOUT): # Yes, logger takes its '*args' as 'args'. self._log(DEBUG_LEVEL_STDOUT, message, args, **kws) # pylint: disable=protected-access