-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Ruff DOC502
preview false positive with requests.Response.raise_for_status()
#12767
Comments
It's a slippery slope to start inferring exception types from arbitrary library code. Perhaps we can cover some of the common cases though. |
I completely agree it's a slippery slope haha. It may also be that functions/methods like |
Adding configuration solves a different need. It allows you to make Ruff behave correctly for your user code or a library that isn't commonly used. I think it would be somewhat annoying if every requests users has to write the same configuration. |
Maybe. We have to draw the line somewhere, though, and "we will attempt to handle stdlib functions but not arbitrary third-party functions that raise exceptions" feels like the logical line for us to draw for me. |
I also just ran into this error! To play devil's advocate. I think this slope is not super slippery, since there aren't that many methods in popular libraries that have the sole purpose of raising an error (afaik). I think expanding this scope to include the I would to be proven wrong. If there are many more methods in popular libraries that have the sole purpose of raising an exception, please let me know! |
Would users necessarily need to encode the exception types as well? That seems a bit overkill. It could be a list of APIs that are known to return |
I think it would be useful, as if not response.ok:
raise requests.exceptions.HTTPError(...) It's just a lazy way to raise an error, so I think it makes sense to include that exception in the docstring. |
Oh, so the return type for Edit: I should have spotted that in original post, sorry. |
With
ruff==0.5.7
and turning on the preview ruleDOC502
/docstring-extraneous-exception
(made as part of #12434), I think perhapsrequests.Response.raise_for_status()
is a special case where we should not alert DOC502 forHTTPError
:Ruff will print what is imo a false positive:
The text was updated successfully, but these errors were encountered: