Use duck-typing to set a quasi-integer response status. #191

wants to merge 3 commits into


None yet

3 participants

perey commented Apr 7, 2015

This change checks for integer values when setting response.status by calling int() on the supplied value, instead of explicitly checking for a subclass of int.

This is helpful to me, because I'm writing code that wraps HTTP statuses in a class that defines __int__(). I'd like to be able to use WebOb together with this class without having to check whether the Response object accepted the status, or whether I need to call int() (or str() for that matter) and try again.

This change additionally removes the need for the "if ' ' not in value" check, which assumed value was interpretable by int() anyway and then performed the same string substitution as the setter for response.status_code.


Can you please fix the failing tests.

@bertjwregeer bertjwregeer added this to the Version 1.5 milestone Apr 7, 2015
@mmerickel mmerickel commented on the diff Apr 13, 2015
@@ -256,11 +260,6 @@ def _status__set(self, value):
raise TypeError(
"You must set status to a string or integer (not %s)"
% type(value))
- if ' ' not in value:
- try:
- value += ' ' + status_reasons[int(value)]
- except KeyError:
- value += ' ' + status_generic_reasons[int(value) // 100]
mmerickel Apr 13, 2015 Member

We are losing some validation here I think.

response.status = 'InvalidStatusCodeString' will pass here and be set when it should fail, right?


I pulled your changes, and rebased them on top of master.

@bertjwregeer bertjwregeer added a commit that referenced this pull request Apr 14, 2015
@bertjwregeer bertjwregeer Rebased and missed part of a patchset
Rebased PR #191, but apparently missed part of the patch. This fixes

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment