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
It's not obvious, but is_successful is a method, so it'll always evaluate as truthy; you'll never run the exit() call here. The correct syntax would've been if not prelim_result.is_successful().
We could make is_successful a property using the @property decorator, or maybe just evaluate it at the time the model is instantiated. With that change, result.is_successful would return the correct boolean value. If someone got it wrong and tried result.is_successful() that would raise an error (TypeError: 'bool' object is not callable), which is much better than the sneaky "always true" bug from the above example.
The text was updated successfully, but these errors were encountered:
mDuo13
changed the title
[FEATURE] [BREAKING] Use @property for Response.is_successful (or just make it an attribute)
Use @property for Response.is_successful (or just make it an attribute)
Mar 24, 2021
Closing since we will do the solution described in 202. It doesn't make sense to me that this boolean method should be exposed as a property while many others in our lib would not.
Can you spot what's wrong with the following code?
It's not obvious, but
is_successful
is a method, so it'll always evaluate as truthy; you'll never run theexit()
call here. The correct syntax would've beenif not prelim_result.is_successful()
.We could make
is_successful
a property using the@property
decorator, or maybe just evaluate it at the time the model is instantiated. With that change,result.is_successful
would return the correct boolean value. If someone got it wrong and triedresult.is_successful()
that would raise an error (TypeError: 'bool' object is not callable
), which is much better than the sneaky "always true" bug from the above example.The text was updated successfully, but these errors were encountered: