Skip to content

chore: make mypy default mode pass with zero errors#6

Merged
acebot712 merged 1 commit intomainfrom
chore/mypy-clean
Apr 18, 2026
Merged

chore: make mypy default mode pass with zero errors#6
acebot712 merged 1 commit intomainfrom
chore/mypy-clean

Conversation

@acebot712
Copy link
Copy Markdown
Owner

Summary

Drives `mypy promptguard/` from 14 errors → 0 with mechanical, behavior-preserving fixes.

All 14 errors were the same shape: a function declared a precise return type (e.g. `dict[str, Any]` or `str | None`) but actually returned `Any` through `response.json()`, `msg.content`, or a similar bridge to an untyped third-party SDK.

Fix: bind the bridge value to a locally typed variable, then return that. The runtime is identical; mypy can now narrow.

Files touched

  • `promptguard/client.py` (×2)
  • `promptguard/patches/_base.py`
  • `promptguard/patches/openai_patch.py` (×4)
  • `promptguard/patches/anthropic_patch.py` (×1)
  • `promptguard/patches/google_patch.py` (×1)
  • `promptguard/patches/cohere_patch.py` (×2)
  • `promptguard/integrations/llamaindex.py` (×2)

Test plan

Verified locally:

```
$ ruff check . # All checks passed!
$ ruff format --check . # 29 files already formatted
$ mypy promptguard/ # Success: no issues found in 20 source files
$ pytest tests/ # 117 passed, 1 skipped
```

Plus a smoke test on the redaction helpers to confirm runtime behavior is identical.

Versioning

No public API change. No dependency change. Patch-bump worthy if you decide to release.

The SDK had 14 [no-any-return] errors across 7 files. Each came from
the same shape: a function declared a precise return type (e.g.
``dict[str, Any]`` or ``str | None``) but actually returned ``Any``
through ``response.json()``, ``msg.content``, or a similar bridge to
an untyped third-party SDK.

Fix is mechanical and behavior-preserving: bind the bridge value to a
locally typed variable, then return that. The runtime is identical;
mypy can now narrow.

Verified: ``mypy promptguard/`` -> "Success: no issues found in 20
source files." All 117 tests still pass. Lint and format are clean.

No public API change. No dependency change. Patch-bump worthy.
@acebot712 acebot712 merged commit dae8c53 into main Apr 18, 2026
8 checks passed
@acebot712 acebot712 deleted the chore/mypy-clean branch April 18, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant