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 class construction regression #418

Closed
vEpiphyte opened this issue Dec 11, 2019 · 0 comments · Fixed by #420
Closed

MultiDict class construction regression #418

vEpiphyte opened this issue Dec 11, 2019 · 0 comments · Fixed by #420

Comments

@vEpiphyte
Copy link

Describe the bug

With multidict 4.7.0, you cannot create a MultiDict with an iterable of key-valu data.

To Reproduce

>>> import sys
>>> import multidict
>>> multidict.__version__
'4.7.0'
>>> sys.version
'3.7.3 (default, Apr 20 2019, 14:54:00) \n[GCC 7.3.0]'
>>> headers=[['User-Agent', 'HTTP Stuff']]
# This is a valid input for the python dict() function
>>> foo = dict(headers)
>>> foo
{'User-Agent': 'HTTP Stuff'}
# Direct MultiDict use failse
>>> multidict.MultiDict(headers)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: MultiDict keys should be either str or subclasses of str
# aiohttp uses CiMultiDict
>>> multidict.CIMultiDict(headers)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: CIMultiDict keys should be either str or subclasses of str

Expected behavior

I expect to make a CIMultiDict / MultiDict with the input list of items.

Logs/tracebacks

Included in the above example.

Your version of the Python

3.7.3 compiled via pyenv on ubuntu 18.04

Your version of the multidict distribution

4.7.0

Additional context

I ran into this with testing aiohttp related calls where headers were being passed as a list of key, value pairs.

aiohttp typedefs their header arguments with a struct they call LooseHeaders defined here https://github.com/aio-libs/aiohttp/blob/v3.6.2/aiohttp/typedefs.py#L42

their docs refer to header arguments as either dicts or list of key/valu pairs https://aiohttp.readthedocs.io/en/stable/client_reference.html#client-session

That is passed into the multidict struct here https://github.com/aio-libs/aiohttp/blob/v3.6.2/aiohttp/client.py#L827

This is valid according to the multidict documentation here:

https://multidict.readthedocs.io/en/stable/multidict.html#multidict

Specifically the line Accepted parameters are the same as for dict.. This is no longer valid with the 4.7.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant