-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[requests] Loosen HTTPError's Response
type
#10766
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`requests` itself allows a `None` type for `Response`; it will internally attempt to read it from the `request` passed. There is thus no strict guarantee that a `HTTPError` will have a truthy `request`. Fixes python#10764
Diff from mypy_primer, showing the effect of this PR on open source code: cloud-init (https://github.com/canonical/cloud-init)
+ cloudinit/url_helper.py:343: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
+ cloudinit/url_helper.py:344: error: Item "None" of "Response | None" has no attribute "headers" [union-attr]
- tests/unittests/sources/azure/test_errors.py:169: error: Missing named argument "response" for "HTTPError" [call-arg]
paasta (https://github.com/yelp/paasta)
- paasta_tools/mesos_maintenance.py:213: error: Missing named argument "response" for "HTTPError" [call-arg]
poetry (https://github.com/python-poetry/poetry)
+ src/poetry/publishing/uploader.py:35: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
+ src/poetry/publishing/uploader.py:35: error: Item "None" of "Response | None" has no attribute "reason" [union-attr]
+ src/poetry/publishing/uploader.py:35: error: Item "None" of "Response | None" has no attribute "content" [union-attr]
twine (https://github.com/pypa/twine)
+ twine/__main__.py:36: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
+ twine/__main__.py:39: error: Item "None" of "Response | None" has no attribute "url" [union-attr]
+ twine/__main__.py:39: error: Item "None" of "Response | None" has no attribute "reason" [union-attr]
materialize (https://github.com/MaterializeInc/materialize)
+ misc/python/materialize/cloudtest/util/web_request.py:27: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
+ misc/python/materialize/cloudtest/util/web_request.py:28: error: Item "None" of "Response | None" has no attribute "reason" [union-attr]
+ misc/python/materialize/cloudtest/util/web_request.py:29: error: Item "None" of "Response | None" has no attribute "content" [union-attr]
+ misc/python/materialize/cloudtest/util/web_request.py:70: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
+ misc/python/materialize/cloudtest/util/web_request.py:102: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
+ misc/python/materialize/cloudtest/util/web_request.py:134: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
+ misc/python/materialize/cloudtest/util/web_request.py:172: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/cli/output/default.py: note: In function "display_service_error":
+ src/schemathesis/cli/output/default.py:357: error: Item "None" of "Optional[Response]" has no attribute "status_code" [union-attr]
+ src/schemathesis/cli/__init__.py: note: In function "handle_service_error":
+ src/schemathesis/cli/__init__.py:1198: error: Item "None" of "Optional[Response]" has no attribute "status_code" [union-attr]
+ src/schemathesis/cli/__init__.py:1199: error: Item "None" of "Optional[Response]" has no attribute "json" [union-attr]
+ src/schemathesis/cli/__init__.py:1200: error: Item "None" of "Optional[Response]" has no attribute "status_code" [union-attr]
+ src/schemathesis/cli/__init__.py: note: In function "login":
+ src/schemathesis/cli/__init__.py:1316: error: Item "None" of "Optional[Response]" has no attribute "json" [union-attr]
apprise (https://github.com/caronc/apprise)
- test/helpers/rest.py:63: error: Missing named argument "response" for "HTTPError" [call-arg]
- test/test_attach_http.py:59: error: Missing named argument "response" for "HTTPError" [call-arg]
- test/test_config_http.py:54: error: Missing named argument "response" for "HTTPError" [call-arg]
openlibrary (https://github.com/internetarchive/openlibrary)
+ openlibrary/catalog/get_ia.py: note: In function "urlopen_keep_trying":
+ openlibrary/catalog/get_ia.py:25: error: Item "None" of "Response | None" has no attribute "status_code" [union-attr]
|
Ah, actually, well, the ecosystem test speaks for itself – this is probably not a good idea. |
And this was also the wrong thing you loosened up. :-) The |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
requests
itself allows aNone
type forResponse
; it will internally attempt to read it from therequest
passed.There is thus no strict guarantee that a
HTTPError
will have a truthyrequest
.Fixes #10764
Follows up on #10740
See https://github.com/psf/requests/blob/881281250f74549f560408e5546d95a8cd73ce28/src/requests/exceptions.py#L17-L24 for the relevant inference code.