-
-
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] Sync HttpError stub to implementation #10875
Conversation
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]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/cli/output/default.py: note: In function "display_service_error":
+ src/schemathesis/cli/output/default.py:368: 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:1233: error: Item "None" of "Optional[Response]" has no attribute "status_code" [union-attr]
+ src/schemathesis/cli/__init__.py:1234: error: Item "None" of "Optional[Response]" has no attribute "json" [union-attr]
+ src/schemathesis/cli/__init__.py:1235: 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:1357: 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]
|
Cf #10764 |
This PR is problematic, as the primer output shows. A lot of code assumes that On the other hand, some code outside requests that constructs Especially considering the test in requests, I propose to accept this PR, even if it means that some code needs asserts or type ignore. It's also the safer alternative. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, see my last comment, but I would like another maintainer to chime in.
There's no way of making everybody happy here, but this approach does have the advantage that it is, well, correct. |
thanks for the comments, I agree it's not super nice to break quite some apps, but at least we're starting to being aligned again with the implementation going forward |
`types-requests` now allows `HTTPError.response` to be `None` and in order to make mypy happy, we need to check for it see python/typeshed#10875 Signed-off-by: Gerd Oberlechner <goberlec@redhat.com>
`types-requests` now allows `HTTPError.response` to be `None` and in order to make mypy happy, we need to check for it see python/typeshed#10875 Signed-off-by: Gerd Oberlechner <goberlec@redhat.com>
`types-requests` now allows `HTTPError.response` to be `None` and in order to make mypy happy, we need to check for it see python/typeshed#10875 Signed-off-by: Gerd Oberlechner <goberlec@redhat.com>
python/typeshed#10875 Signed-off-by: Anders Kaseorg <anders@zulip.com>
python/typeshed#10875 Signed-off-by: Anders Kaseorg <anders@zulip.com>
python/typeshed#10875 Signed-off-by: Anders Kaseorg <anders@zulip.com>
FWIW I think this is a step backwards. |
@intgr In the end, this is an issue to be taken up with the requests project. It would make sense to me that |
This change has caused quite a lot of busy work for us as well. I think that in practice, it would have been better to leave |
is there any way to change this so that by default it has |
I think this should be reverted. As already mentioned, the only place in requests that raises if http_error_msg:
raise HTTPError(http_error_msg, response=self) So practically, when you do IMO the unit test that initializes response to Is there really a practical problem that this PR solves, and is it really worth solving? If there is, and I'm just unaware of it, I'd suggest using the Any trick (now documented in CONTRIBUTING.md). |
The practical problem is that people initialize |
This reverts commit e92bfcb.
Not really, but we did the next best thing in #11207: you can now assume it has a |
The implementation has no restrictions on providing a response. Is there a reason why the stub requires it?