Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
karpetrosyan opened this issue Jul 28, 2023 Discussed in #2793 · 0 comments · Fixed by #2803
Closed

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

karpetrosyan opened this issue Jul 28, 2023 Discussed in #2793 · 0 comments · Fixed by #2803

Comments

@karpetrosyan
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant