diff --git a/src/werkzeug/datastructures.py b/src/werkzeug/datastructures.py index 8ff359744..1c7b27da6 100644 --- a/src/werkzeug/datastructures.py +++ b/src/werkzeug/datastructures.py @@ -355,6 +355,12 @@ def __setstate__(self, value): dict.clear(self) dict.update(self, value) + def __iter__(self): + # Work around https://bugs.python.org/issue43246. + # (`return super().__iter__()` also works here, which makes this look + # even more like it should be a no-op, yet it isn't.) + return dict.__iter__(self) + def __getitem__(self, key): """Return the first data value for this key; raises KeyError if not found. diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py index 7249faa8f..c940ae85b 100644 --- a/tests/test_datastructures.py +++ b/tests/test_datastructures.py @@ -70,6 +70,14 @@ def create_instance(module=None): ud[b"newkey"] = b"bla" assert ud != d + def test_multidict_dict_interop(self): + # This would have caught the regression in Werkzeug 2.0.0rc1 + # (see https://github.com/pallets/werkzeug/pull/2043). + md = self.storage_class([("a", 1), ("a", 2)]) + assert dict(md)["a"] != [1, 2] + assert dict(md)["a"] == 1 + assert dict(md) == {**md} == {"a": 1} + def test_basic_interface(self): md = self.storage_class() assert isinstance(md, dict)