Skip to content

Fix mypy error caused by requests 2.34.1 HeadersType change#143

Closed
fpfp100 wants to merge 1 commit into
microsoft:mainfrom
fpfp100:fix-mypy-requests-headers-type
Closed

Fix mypy error caused by requests 2.34.1 HeadersType change#143
fpfp100 wants to merge 1 commit into
microsoft:mainfrom
fpfp100:fix-mypy-requests-headers-type

Conversation

@fpfp100
Copy link
Copy Markdown
Contributor

@fpfp100 fpfp100 commented May 13, 2026

Summary

  • requests 2.34.1 changed HeadersType from Mapping[str, str | bytes] to MutableMapping[str, str | bytes], which causes mypy to reject dict[str, str] due to MutableMapping's invariant value type parameter.
  • Updated _post_with_retries signature to use MutableMapping[str, str | bytes] to match the new type.

Test plan

  • Verify mypy passes in CI (Black, Pylint, and Mypy job)
  • Verify all pytest jobs pass

🤖 Generated with Claude Code

requests 2.34.1 changed HeadersType from Mapping[str, str | bytes] to
MutableMapping[str, str | bytes], which causes mypy to reject dict[str, str]
due to MutableMapping's invariant value type parameter. Update the
_post_with_retries signature to match the new expected type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to resolve a mypy type-checking failure introduced by requests==2.34.1 changing its header type alias to use MutableMapping[str, str | bytes], by updating the internal _post_with_retries helper to accept the new header type.

Changes:

  • Import MutableMapping for typing from collections.abc.
  • Update _post_with_retries(..., headers=...) to accept MutableMapping[str, str | bytes].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return text

def _post_with_retries(self, url: str, body: str, headers: dict[str, str]) -> bool:
def _post_with_retries(self, url: str, body: str, headers: MutableMapping[str, str | bytes]) -> bool:
@fpfp100 fpfp100 closed this May 13, 2026
@fpfp100 fpfp100 deleted the fix-mypy-requests-headers-type branch May 13, 2026 23:32
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.

3 participants