Skip to content

Change the type of Extensions from Mapping to MutableMapping. #2794

Closed

Description

@karpetrosyan

Discussed in #2793

Originally posted by karosis88 July 28, 2023
I'm working on a library that implements HTTP Caching for httpx and httpcore (it provides transports and connection pools), and I'd like to add an extension that simply indicates whether or not the response was taken from the cache.

Unfortunately, the type of extension is Mapping, so this is an error for mypy.

response = httpx.Response(200)
response.extensions['my_custom_extension'] = 'something'

OUTPUT

error: Unsupported target for indexed assignment ("Mapping[Str, Any]")  [index]

The solution is to simply change the extension type from Mapping to MutableMapping, allowing us to add custom extensions after the response has been created.

See also this pr


I believe the only change needed is in the "_models.py" file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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