Fix: mypy warns about invalid types for json argument
Fixed psf/requests#7443 — 1 line type-annotation. 407/407 relevant tests pass
The Bug
Repo: psf/requests Issue: #7443 Status: PR-submitted PR: https://github.com/psf/requests/pull/7449
Description: mypy warns about invalid types for json argument
Fix scope: 1 line changed in src/requests/_types.py
The Fix
This is a trivial fix. The change is minimal and targeted — only what’s needed.
@@ -144,7 +144,7 @@ if TYPE_CHECKING:
| float
| str
| Sequence["JsonType"]
- | Mapping[str, "JsonType"]
+ | Mapping[str, Any]
)
What This Teaches
Type annotations in Python are not just documentation — they affect tooling. mypy --strict
checks every union branch, and recursive type aliases with Mapping[str, "JsonType"] create
an infinite recursion that mypy cannot resolve.
The fix replaces the self-referencing type with Any, which preserves the intent
(the parameter accepts any JSON-serializable mapping) while satisfying mypy’s type checker.
Pattern: When a type alias is too recursive for mypy, use Any at the boundary.
Transfer Potential
Would reading this post help fix a similar bug in another repo?
High — type annotation issues follow a consistent pattern across projects. Any Python repo with mypy strict mode could benefit from this pattern.
Auto-generated from PR #7443. View all patches on GitHub.