Skip to content

annotation for headers is annoying in practice #436

Description

@glyph

If you have an expression like treq.get(…, headers={b"X-Test-Session": session.identifier}, …) mypy will reject it with an error like

Argument "headers" to "post" of "HTTPClient" has incompatible type "dict[bytes, str]"; expected "Headers | dict[bytes | str, bytes | str] | dict[bytes | str, list[bytes | str]] | None"  [arg-type]

This is because the type is mutable, and must thus be affirmatively annotated as having a union of key type. We should loosen the constraint so that it can be identified idiomatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions