From 37534d4ef45ab2787639394b4deecf5a87c08575 Mon Sep 17 00:00:00 2001 From: Allan Beaufour Date: Sat, 27 Jun 2026 17:32:40 -0400 Subject: [PATCH] Fix mypy errors, add mypy config, and run mypy in CI - method_call.py: narrow `_RATE_LIMIT_REQUESTS_PER_HOUR` with an explicit if/else so the `float / None` operand error is gone, without duplicating the None check. - pyproject.toml: add a [tool.mypy] section with ignore_missing_imports overrides for `requests_oauthlib` (no stubs) and `PIL` (optional, not installed by default). - ci.yml: add a `mypy` step to the lint job so type errors are caught in CI and don't regress. `uv run mypy flickr_api/` is now clean (was 3 errors). flake8, ruff check, ruff format --check, and all 282 tests still pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/ci.yml | 3 +++ flickr_api/method_call.py | 8 ++++++-- pyproject.toml | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90f2120..af53c62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,9 @@ jobs: - name: Run ruff format check run: uv run ruff format --check flickr_api/ + - name: Run mypy + run: uv run mypy flickr_api/ + test: runs-on: ubuntu-latest strategy: diff --git a/flickr_api/method_call.py b/flickr_api/method_call.py index 10a13b1..3a0ccf8 100644 --- a/flickr_api/method_call.py +++ b/flickr_api/method_call.py @@ -165,8 +165,12 @@ def get_rate_limit_status() -> dict[str, Any]: - interval_seconds: float - Minimum time between requests (0.0 if disabled) - last_request_time: float | None - Timestamp of last request """ - enabled = _RATE_LIMIT_REQUESTS_PER_HOUR is not None - interval = 3600.0 / _RATE_LIMIT_REQUESTS_PER_HOUR if enabled else 0.0 + if _RATE_LIMIT_REQUESTS_PER_HOUR is not None: + enabled = True + interval = 3600.0 / _RATE_LIMIT_REQUESTS_PER_HOUR + else: + enabled = False + interval = 0.0 return { "enabled": enabled, "requests_per_hour": _RATE_LIMIT_REQUESTS_PER_HOUR, diff --git a/pyproject.toml b/pyproject.toml index d5d1177..a21d333 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,3 +48,17 @@ testpaths = ["test"] [tool.ruff] line-length = 100 + +[tool.mypy] +python_version = "3.10" + +# Third-party libraries without type information. `requests_oauthlib` ships no +# stubs, and `PIL` (Pillow) is an optional runtime dependency that is not +# installed by default. +[[tool.mypy.overrides]] +module = [ + "requests_oauthlib", + "PIL", + "PIL.*", +] +ignore_missing_imports = true