Visitar URL original
Return `str | None` instead of `Any` from `Headers.get` by ItsDrike · Pull Request #1121 · pydantic/httpx2 · GitHub
Skip to content

Return str | None instead of Any from Headers.get - #1121

Merged
Kludex merged 3 commits into
pydantic:mainfrom
ItsDrike:fix-headers-get-signature
Aug 9, 2026
Merged

Kludex merged 3 commits into
pydantic:mainfrom
ItsDrike:fix-headers-get-signature

Conversation

@ItsDrike

@ItsDrike ItsDrike commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This fixes the loose type signature that relied on typing.Any in Headers.get with a type-safe signature that directly matches the parent MutableMapping[str, str] definition and leads to a concrete return type.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
    • The tests don't seem to apply to this change, as it's just a typing signature change
  • I've updated the documentation accordingly.
    • Does not seem to apply for this change

Review in cubic

@codspeed

codspeed Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing ItsDrike:fix-headers-get-signature (039e6fb) with main (dec24ad)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@ItsDrike
ItsDrike marked this pull request as ready for review August 7, 2026 09:28

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Kludex added 2 commits August 9, 2026 10:04
Also drops the redundant `default: str` overload on `Headers.get` (the generic one already collapses to `str`) and renames the type variable to `_T`.

`Cookies.get` no longer needs its `# type: ignore`: the overloads are override-compatible with `MutableMapping.get`.
@Kludex Kludex changed the title Improve the type signature of Headers.get Return str | None instead of Any from Headers.get Aug 9, 2026
@Kludex
Kludex merged commit dee1d1a into pydantic:main Aug 9, 2026
15 checks passed
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.

2 participants