You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I fail to see a use case were you would want to discard any errors (no logs, no treatment at all) and only perform action in case of successful response. This would be the only use case for a if response.ok and it seems like bad practice. Do you have such use case ?
I fail to see a use case were you would want to discard any errors (no logs, no treatment at all) and only perform action in case of successful response. This would be the only use case for a if response.ok and it seems like bad practice. Do you have such use case ?
See #809
I fail to see a use case were you would want to discard any errors (no logs, no treatment at all) and only perform action in case of successful response. This would be the only use case for a if response.ok and it seems like bad practice. Do you have such use case ?
I don't, I'm just a sassy opinionated coder
So you don't need to use if not, you can replace your:
So, the reason we don't do this is pretty clear.
As a developer, what do you think response.okmeans?
response.status_code == 200A "200 OK" response
response.status_code >= 200 and response.status_code <= 299Any 2xx response
not response.is_errorNot a "4xx, 5xx" response
It's just not at all clear. (Incidentally, in requests it means the last one of those.)
I could perhaps see us having response.is_success, response.is_client_error and response.is_server_error properties., which are way more obviously 2xx, 4xx, and 5xx classes of response. But... note that would open up easy coding error classes like...
Which doesn't do what it might look like it does on first sight.
So... sure if not response.is_error ain't got as much sass as if response.ok, or even if response.is_success, but it'll help prevent coding errors.
(I mean there's other options too. For instance, response.is_2xx, response.is_3xx, etc... but in terms of requests-parity I'm pretty convinced we don't want the misleading response.ok)
Activity
lovelydinosaur commentedon Dec 2, 2020
We've got a comment in the "requests compatibility" docs about this.
StephenBrown2 commentedon Dec 2, 2020
Link to aforementioned docs: https://www.python-httpx.org/compatibility#checking-for-4xx5xx-responses
serg06 commentedon Mar 14, 2021
if not resp.is_errorjust doesn't hit the same asif resp.ok🙁Colin-b commentedon Mar 14, 2021
See #809
I fail to see a use case were you would want to discard any errors (no logs, no treatment at all) and only perform action in case of successful response. This would be the only use case for a
if response.okand it seems like bad practice. Do you have such use case ?serg06 commentedon Mar 14, 2021
I don't, I'm just a sassy opinionated coder
Colin-b commentedon Mar 14, 2021
So you don't need to use
if not, you can replace your:by:
And then you have it, no negation involved :)
serg06 commentedon Mar 14, 2021
But then I'd be putting the (unlikely) error case before the (likely) success case!
lovelydinosaur commentedon Mar 14, 2021
Them's the breaks.
lovelydinosaur commentedon Mar 22, 2021
So, the reason we don't do this is pretty clear.
As a developer, what do you think
response.okmeans?response.status_code == 200A "200 OK" responseresponse.status_code >= 200 and response.status_code <= 299Any 2xx responsenot response.is_errorNot a "4xx, 5xx" responseIt's just not at all clear. (Incidentally, in requests it means the last one of those.)
I could perhaps see us having
response.is_success,response.is_client_errorandresponse.is_server_errorproperties., which are way more obviously 2xx, 4xx, and 5xx classes of response. But... note that would open up easy coding error classes like...Which doesn't do what it might look like it does on first sight.
So... sure
if not response.is_errorain't got as much sass asif response.ok, or evenif response.is_success, but it'll help prevent coding errors.(I mean there's other options too. For instance,
response.is_2xx,response.is_3xx, etc... but in terms of requests-parity I'm pretty convinced we don't want the misleadingresponse.ok)