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

MultiDict.values - incorrect implementation in python 3 #1113

Open
akva opened this issue Nov 27, 2018 · 2 comments
Open

MultiDict.values - incorrect implementation in python 3 #1113

akva opened this issue Nov 27, 2018 · 2 comments
Labels
Change Neigher a bug nor a freature, but something that needs to be addressed.

Comments

@akva
Copy link

akva commented Nov 27, 2018

bottle/bottle.py

Line 2112 in 9fb3b05

return (v[-1] for v in self.dict.values())

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 defnull added the Change Neigher a bug nor a freature, but something that needs to be addressed. label Nov 27, 2018
@defnull
Copy link
Member

defnull commented Nov 27, 2018

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
Copy link
Author

akva commented Nov 27, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Change Neigher a bug nor a freature, but something that needs to be addressed.
Projects
None yet
Development

No branches or pull requests

2 participants