Last active
December 11, 2015 21:28
-
-
Save dcramer/4662375 to your computer and use it in GitHub Desktop.
Because you should maintain API compatibility when you tell everyone to use your shit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from requests.models import Response | |
class fixedjson(object): | |
def __init__(self, func): | |
self.func = func | |
def __get__(self, inst, cls): | |
result = self.func(inst) | |
class proxy(type(result)): | |
def __call__(self): | |
return self | |
if isinstance(result, (dict, int, float, unicode, str, tuple, list)): | |
return proxy(result) | |
elif result is None: | |
return proxy() | |
else: | |
raise NotImplementedError | |
return proxy | |
Response.json = fixedjson(Response.json) | |
import requests | |
x = requests.get('http://httpbin.org/ip') | |
print repr(x.json) | |
print repr(x.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Out of curiosity, not nitpicking, isn't line 21 unreachable?