Skip to content

mypy warns about invalid types for headers #7442

@hmoffatt

Description

@hmoffatt

Using requests with types-requests 2.33 I had no warnings, but now using requests 2.34.1's in-built type hints I have this new warning in multiple places:

error: Argument "headers" to "post" has incompatible type "dict[str, str]"; expected "MutableMapping[str, str | bytes] | None"  [arg-type]

This did not issue a warning in v2.34.0.

Expected Result

No warning.

Actual Result

Warning issued.

Reproduction Steps

import requests

def x() -> None:
    headers = {"hi": "there"}
    requests.post("https://google.com", headers=headers)

System Information

$ python -m requests.help
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "3.4.7"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.15"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.13.5"
  },
  "platform": {
    "release": "6.12.74+deb13+1-amd64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.34.1"
  },
  "system_ssl": {
    "version": "30500050"
  },
  "urllib3": {
    "version": "2.7.0"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions