diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3680700..a50d88d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,10 +37,10 @@ repos: exclude: "(^Pipfile\\.lock$)" # Python hooks - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.0.292' + rev: 'v0.1.0' hooks: - id: ruff - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.10.0 hooks: - id: black diff --git a/pyproject.toml b/pyproject.toml index b11e949..14cc037 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,7 @@ python = ["3.8", "3.9", "3.10", "3.11", "3.12"] [tool.hatch.envs.pre-commit] dependencies = [ - "pre-commit>=3.4.0", + "pre-commit>=3.5.0", ] [tool.hatch.envs.pre-commit.scripts] @@ -101,8 +101,8 @@ update = ["pre-commit autoupdate"] detached = true dependencies = [ "black>=23.9.1", - "mypy>=1.0.0", - "ruff>=0.0.292", + "mypy>=1.6.0", + "ruff>=0.1.0", "httpx", ] @@ -112,6 +112,7 @@ typing = [ "mypy --install-types --non-interactive {args:src/gotenberg_client}" ] style = [ + "ruff --version", "ruff {args:.}", "black --check --diff {args:.}", ] @@ -135,25 +136,33 @@ fix = true output-format = "grouped" target-version = "py38" line-length = 120 +# https://docs.astral.sh/ruff/rules/ extend-select = [ "A", "ARG", "B", "C", + "C4", "COM", "DTZ", "E", "EM", + "ERA", "EXE", "F", "FBT", + "FLY", "I", "ICN", "INP", + "INT", "ISC", "N", + "PERF", "PIE", + "PGH", "PTH", + "PL", "PLC", "PLE", "PLR", @@ -164,8 +173,14 @@ extend-select = [ "RUF", "S", "SIM", + "SLF", "T", + "T10", + "T20", + "TCH", + "TD", "TID", + "TRY", "UP", "W", "YTT", @@ -179,6 +194,8 @@ ignore = [ "S105", "S106", "S107", # Ignore complexity "C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915", + # Ignore no author and missing issue link in TODO tags + "TD002", "TD003" ] [tool.ruff.isort] diff --git a/src/gotenberg_client/_base.py b/src/gotenberg_client/_base.py index 4beb317..ed9b333 100644 --- a/src/gotenberg_client/_base.py +++ b/src/gotenberg_client/_base.py @@ -87,7 +87,7 @@ def get_files(self) -> RequestFiles: {filename: (filename, self._stack.enter_context(file_path.open("rb")), mime_type)}, ) else: # pragma: no cover - files.update({filename: (filename, self._stack.enter_context(file_path.open("rb")))}) # type: ignore + files.update({filename: (filename, self._stack.enter_context(file_path.open("rb")))}) # type: ignore [dict-item] return files def _add_file_map(self, filepath: Path, name: Optional[str] = None) -> None: diff --git a/src/gotenberg_client/_client.py b/src/gotenberg_client/_client.py index 6a8ce84..dc6bf4c 100644 --- a/src/gotenberg_client/_client.py +++ b/src/gotenberg_client/_client.py @@ -37,7 +37,6 @@ def __init__( logging.getLogger("httpx").setLevel(log_level) logging.getLogger("httpcore").setLevel(log_level) - # TODO Brotli? if find_spec("brotli") is not None: self._client.headers.update({"Accept-Encoding": "gzip,deflate,br"}) else: @@ -49,7 +48,6 @@ def __init__( self.pdf_a = PdfAApi(self._client) self.merge = MergeApi(self._client) self.health = HealthCheckApi(self._client) - # TODO def add_headers(self, header: Dict[str, str]) -> None: # pragma: no cover """ diff --git a/src/gotenberg_client/_health.py b/src/gotenberg_client/_health.py index 3f717bc..479ee74 100644 --- a/src/gotenberg_client/_health.py +++ b/src/gotenberg_client/_health.py @@ -78,9 +78,9 @@ def _extract_status(self, module: ModuleOptions) -> ModuleStatus: status = StatusOptions(self.data["details"][module.value]["status"]) # mypy is quite wrong here, it's clearly marked as a datetime.datetime, not Any - timestamp = self._extract_datetime(self.data["details"][module.value]["timestamp"]) # type: ignore - # Also wrong here - return ModuleStatus(status, timestamp) # type: ignore + # but ... + timestamp: datetime.datetime = self._extract_datetime(self.data["details"][module.value]["timestamp"]) + return ModuleStatus(status, timestamp) @staticmethod @no_type_check diff --git a/src/gotenberg_client/_utils.py b/src/gotenberg_client/_utils.py index 5c80146..72977aa 100644 --- a/src/gotenberg_client/_utils.py +++ b/src/gotenberg_client/_utils.py @@ -33,9 +33,9 @@ def guess_mime_type_magic(url: Path) -> Optional[str]: """ Uses libmagic to guess the mimetype """ - import magic # type: ignore + import magic # type: ignore [import-not-found] - return magic.from_file(url, mime=True) # type: ignore + return magic.from_file(url, mime=True) # type: ignore [misc] # Use the best option