>>> from urllib.request import urlopen
>>> urlopen('https://example.com')
<http.client.HTTPResponse object at 0x7fc608f39fd0>
>>> resp = urlopen('https://example.com')
>>> resp.headers['foo']
>>> resp.headers['connection']
'close'
>>> type(resp.headers['connection'])
<class 'str'>
import urllib.request
from typing import Optional
resp = urllib.request.urlopen('https://example.com')
x: Optional[str] = resp.headers['connection']
$ mypy t.py
t.py:5: error: Incompatible types in assignment (expression has type "Union[str, Header, None]", variable has type "Optional[str]")
If this sounds sane, I'd like to add __getitem__ here?
If this sounds sane, I'd like to add
__getitem__here?