-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Wrong type for hdrs in urllib.error.HTTPError #10092
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
Comments
Where do you see that in the stdlib code? The only instances I see where |
All those functions in
and then adds headers with: def add_header(self, key, val):
# useful for something like authentication
self.headers[key.capitalize()] = val |
I'm not sure why our stubs say the handler methods expect a So I think the best option is to indeed change |
Checking the history, the PR which added this is: #5854 And trying a sample code, looks like (HTTP)Message is the correct type, which also implements some Mapping methods, but it's not the other way around. import urllib.error
import urllib.request
try:
urllib.request.urlopen('https://jigsaw.w3.org/HTTP/Basic/')
except urllib.error.HTTPError as ex:
print(type(ex.headers)) # <class 'http.client.HTTPMessage'> Which is according to the docs: @srittau Do you still think the change is required? |
Example code
code.py
:mypy complains:
Looking at the Python stdlib code,
hdrs
is always adict[str, str]
.The text was updated successfully, but these errors were encountered: