theelous3 / asks

Async requests-like httplib for python.
MIT License
508 stars 63 forks source link

convenience attribute `Response.ok` #81

Open carlwgeorge opened 6 years ago

carlwgeorge commented 6 years ago

requests Response objects have an ok attribute that I enjoy using.

http://docs.python-requests.org/en/master/api/#requests.Response.ok

Please implement this in asks.

theelous3 commented 6 years ago

I get that people like this in requests, but it's just so vague I don't see how it's useful. When do you not care if you get a 200 or crazy stuff like a 306 or 301, or even 205?

200 <= r.status_code < 400 does the same thing and is explicit about the vague check that's happening.

I'll leave this issue open for a while and if there are any more bites I'll throw it in.

If you happen to just PR it, I'll merge.

carlwgeorge commented 6 years ago

It's certainly not essential, just some nice syntactic sugar. I like the readability of if response.ok:. I think it helps make asks easy to use for someone familiar with requests.

I peeked at how requests does this, and they make use of their raise_for_status method, so I'll try to implement something similar to handle this and #82 at the same time.