-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Should HTTPMessage return Optional[str]
for __getitem__
?
#2333
Comments
Does it never return |
I can't seem to find a situation where it returns |
from the last paragraph of intro, just above https://docs.python.org/3.5/library/email.message.html#email.message.Message.__len__ |
Interesting! Though it doesn't appear to be true for while true; do echo -e "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nWat: $(python -c 'print("\u2603")')\r\n" | nc -l localhost 1500; done $ python3
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.request import urlopen
>>> x = urlopen('http://localhost:1500')
>>> x.headers
<http.client.HTTPMessage object at 0x7f51af37ae80>
>>> x.headers['Wat']
'â\x98\x83'
>>> type(x.headers['Wat'])
<class 'str'> Some pretty sick mojibake though :) |
I think the right solution is to override |
this seems worse now, it's |
Taking a look at this test run: https://github.com/Avasam/typeshed/pull/36/files#diff-ced02b01b42b244e9b7bc2e12ef7a215bde89a29072c99ade903f58fb83a3bc7R36 spack would have to change their assert to first store the value in a local variable then assert that variable: https://github.com/spack/spack/blob/develop/lib/spack/spack/oci/oci.py#L138-L142 twine implicitely uses _, header = msg.policy.header_store_parse("content-type", value)`
return msg.get_content_type(), header.params urllib3 is a false-positive, and an interesting one: https://github.com/urllib3/urllib3/blob/main/src/urllib3/contrib/emscripten/fetch.py#L382C24-L382C24 I'm tempted to say that, from a user code PoV, you should just use As for the type currently being If |
If this sounds sane, I'd like to add
__getitem__
here?The text was updated successfully, but these errors were encountered: