requests icon indicating copy to clipboard operation
requests copied to clipboard

return response from `raise_for_status`

Open soxofaan opened this issue 3 years ago • 1 comments
trafficstars

I'd guess this has been requested before, but couldn't find any pointers so far. (I also understand that requests does not accept feature requests, but this is code-wise a trivial one-line change, so I'm going to try anyway :smile: ).

Feature request: return self from Response.raise_for_status() (instead of returning None implicitly).

That allows using it in a compact chained/fluent manner, for example

data = [
    requests.get(url).raise_for_status().json()
    for url in urls
]

With the current raise_for_status you can not use list comprehension like in this examle because you have to use separate statements for the .get(), .raise_for_status() and .json() .

(An alternative solution could be to add some kind of raise_for_status opt-in option to .get() and alike, but that would require a lot more code changes than a simple return self as proposed higher)

soxofaan avatar Aug 18 '22 09:08 soxofaan

This project is in indefinite feature-freeze and not changing the API in ways that may be surprising for existing users. Also I'm certain this has been requested before but am on mobile and can't easily search

sigmavirus24 avatar Aug 18 '22 17:08 sigmavirus24

I am junior SDE, and I want to contribute to open source. This is my first time. Can I work on this ?

ThugNinja4708 avatar Oct 28 '23 09:10 ThugNinja4708

This project is in indefinite feature-freeze

@sigmavirus24 Is this still true?? Why is it in a feature-freeze?

sohang3112 avatar Feb 27 '24 04:02 sohang3112

Why is it in a feature-freeze?

It's documented here: https://requests.readthedocs.io/en/latest/dev/contributing/#feature-requests

Mariatta avatar Feb 27 '24 05:02 Mariatta