From 3eafa3ce7291336fa252430f5db423cc7f5e7dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20T=C3=A9tard?= Date: Fri, 27 Sep 2024 11:36:12 +0200 Subject: [PATCH] refactor: Apply Ruff linter --- sekoia_automation/aio/helpers/__init__.py | 3 ++- sekoia_automation/cli.py | 3 +-- sekoia_automation/http/aio/http_client.py | 16 ++++++++-------- sekoia_automation/scripts/action_runner.py | 7 +++---- sekoia_automation/utils.py | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/sekoia_automation/aio/helpers/__init__.py b/sekoia_automation/aio/helpers/__init__.py index b11e9eb..6e153fc 100644 --- a/sekoia_automation/aio/helpers/__init__.py +++ b/sekoia_automation/aio/helpers/__init__.py @@ -5,7 +5,8 @@ """ import asyncio -from typing import Any, AsyncGenerator +from collections.abc import AsyncGenerator +from typing import Any async def limit_concurrency(tasks: list, limit: int) -> AsyncGenerator[Any, None]: diff --git a/sekoia_automation/cli.py b/sekoia_automation/cli.py index 78f62f5..1a7c595 100644 --- a/sekoia_automation/cli.py +++ b/sekoia_automation/cli.py @@ -18,8 +18,7 @@ help="Sekoia.io's automation helper to generate playbook modules", rich_markup_mode="markdown", ) -OptionalPath = Optional[Path] -OptionalStr = Optional[str] +OptionalStr = Optional[str] # noqa: UP007 @app.command(name="generate-files-from-code") diff --git a/sekoia_automation/http/aio/http_client.py b/sekoia_automation/http/aio/http_client.py index 3cf9f85..a472874 100644 --- a/sekoia_automation/http/aio/http_client.py +++ b/sekoia_automation/http/aio/http_client.py @@ -3,7 +3,7 @@ import asyncio from collections.abc import AsyncGenerator from contextlib import asynccontextmanager -from typing import Any, Optional +from typing import Any from aiohttp import ClientResponse, ClientResponseError, ClientSession from aiohttp.web_response import Response @@ -56,7 +56,7 @@ async def session(self) -> AsyncGenerator[ClientSession, None]: @asynccontextmanager async def get( - self, url: str, *args: Any, **kwargs: Optional[Any] + self, url: str, *args: Any, **kwargs: Any | None ) -> AsyncGenerator[ClientResponse, None]: """ Get callable. @@ -74,7 +74,7 @@ async def get( @asynccontextmanager async def post( - self, url: str, *args: Any, **kwargs: Optional[Any] + self, url: str, *args: Any, **kwargs: Any | None ) -> AsyncGenerator[ClientResponse, None]: """ Post callable. @@ -92,7 +92,7 @@ async def post( @asynccontextmanager async def put( - self, url: str, *args: Any, **kwargs: Optional[Any] + self, url: str, *args: Any, **kwargs: Any | None ) -> AsyncGenerator[ClientResponse, None]: """ Put callable. @@ -110,7 +110,7 @@ async def put( @asynccontextmanager async def delete( - self, url: str, *args: Any, **kwargs: Optional[Any] + self, url: str, *args: Any, **kwargs: Any | None ) -> AsyncGenerator[ClientResponse, None]: """ Delete callable. @@ -128,7 +128,7 @@ async def delete( @asynccontextmanager async def patch( - self, url: str, *args: Any, **kwargs: Optional[Any] + self, url: str, *args: Any, **kwargs: Any | None ) -> AsyncGenerator[ClientResponse, None]: """ Patch callable. @@ -146,7 +146,7 @@ async def patch( @asynccontextmanager async def head( - self, url: str, *args: Any, **kwargs: Optional[Any] + self, url: str, *args: Any, **kwargs: Any | None ) -> AsyncGenerator[ClientResponse, None]: """ Head callable. @@ -164,7 +164,7 @@ async def head( @asynccontextmanager async def request_retry( - self, method: str, url: str, *args: Any, **kwargs: Optional[Any] + self, method: str, url: str, *args: Any, **kwargs: Any | None ) -> AsyncGenerator[ClientResponse, None]: """ Request callable. diff --git a/sekoia_automation/scripts/action_runner.py b/sekoia_automation/scripts/action_runner.py index dad770e..e4175f4 100644 --- a/sekoia_automation/scripts/action_runner.py +++ b/sekoia_automation/scripts/action_runner.py @@ -2,9 +2,8 @@ import importlib.util import json import sys -import typing from pathlib import Path -from typing import Any, Tuple +from typing import Any from jsonschema import validate @@ -28,7 +27,7 @@ def __init__( if str(self.__module_path) not in sys.path: sys.path.append(str(self.__module_path)) - def load_class_from_path(self, path: Path | str, class_name: str) -> typing.Type: + def load_class_from_path(self, path: Path | str, class_name: str) -> type: # Load the module module_name = ( str(Path(path).resolve().relative_to(self.__root_path)) @@ -61,7 +60,7 @@ def find_file_with_module_item_class(self) -> Path: def find_file_with_child_class( self, parent_class_to_find: str - ) -> Tuple[str | None, Path | None]: + ) -> tuple[str | None, Path | None]: for file_path in self.__module_path.rglob("*.py"): with open(file_path) as f: try: diff --git a/sekoia_automation/utils.py b/sekoia_automation/utils.py index 9952f1c..c38ad05 100644 --- a/sekoia_automation/utils.py +++ b/sekoia_automation/utils.py @@ -1,6 +1,6 @@ +from collections.abc import Sequence from functools import wraps from inspect import get_annotations, getmro -from typing import Sequence import sentry_sdk from pydantic import BaseModel