bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.38k stars 1.46k forks source link

MultiDict.values - incorrect implementation in python 3 #1113

Open akva opened 5 years ago

akva commented 5 years ago

https://github.com/bottlepy/bottle/blob/9fb3b05846b33e508545a26e424785e151d02323/bottle.py#L2112

Assuming MultiDict supports dict protocol (which docstring suggests it does - ".., but behaves exactly like a normal dict.."), .values implementation is not correct. The returned object should be a view which, among other things, supports len. See https://docs.python.org/3/library/stdtypes.html?#dict-views

defnull commented 5 years ago

So we basically need to implement a view-wrapper that applies a function to each value, but otherwise behaves like a view? There is nothing like this in the stdlib I think.

akva commented 5 years ago

This project does it correctly afaict: https://github.com/aio-libs/multidict/blob/master/multidict/_multidict_py.py

WebOb gets it wrong as well btw: https://github.com/Pylons/webob/blob/master/src/webob/multidict.py#L318

Another option would be to simply not support dict protocol. From my personal perspective MultiDict has a pretty narrow use case, namely to support FormsDict. And to handle web forms one doesn't need the whole richness of the dict. Would make the implementation much simpler. But that's my two cents.