aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.67k stars 1.01k forks source link

Set list as an item in MultiDict #2105

Open tfotis opened 6 months ago

tfotis commented 6 months ago

It would be nice if there can be a way to set a list as an item in a MultiDict object.

This is currently only possible if you re-create the object.

Examples

from chalice.app import MultiDict
m = MultiDict(None)
m["a"] = ["a1", "a2"]
print(m)
// MultiDict({'a': [['a1', 'a2']]})  # list is inserted in a list
from chalice.app import MultiDict
m = MultiDict({"a": ["a1", "a2"]})
print(m)
// MultiDict({'a': ['a1', 'a2']})  # list is OK, as it was provided during object creation

So maybe the correct functionality for __setitem__ would be the following:

from chalice.app import MultiDict
m = MultiDict(None)
m["a"] = ["a1", "a2"]
print(m)
// MultiDict({'a': ['a1', 'a2']})