Unable to merge MutableHeaders with dict #1515
-
Checklist
Describe the bugUnable to merge To reproducefrom starlette.datastructures import MutableHeaders
response = MutableHeaders()
response |= {"X-Header": "string"} Expected behavior>>> response
MutableHeaders({'x-header': 'string'}) Actual behaviorRaised exception:
Environment
Additional contextMethod It's comfortable if you have many headers like: ...
headers = {
"X-Header-1": "string-1",
"X-Header-1": "string-2",
"X-Header-3": "string-3",
"X-Header-...": "string-...",
"X-Header-N": "string-N",
}
response.headers |= headers # equals to: response.headers.update(headers)
return response
... It's like Dictionary Merge & Update Operators in Python 3.9. What do you think about it? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
imho this is a cPython bug. _collections_abc.Mapping should define these mixin methods |
Beta Was this translation helpful? Give feedback.
-
Based on PEP-584, it does look like a CPython bug 🤔 EDIT: I've read it again, and is not a bug on CPython. It's as intended. |
Beta Was this translation helpful? Give feedback.
Based on PEP-584, it does look like a CPython bug 🤔
EDIT: I've read it again, and is not a bug on CPython. It's as intended.