From: Cory Benfield Date: Sat, 24 Nov 2012 12:15:30 +0000 (+0000) Subject: Avoid using callable(). X-Git-Tag: v1.0.0~104^2~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5f9a2a51c884099294f75ae9148ec0f64b0bab4;p=services%2Fpython-requests.git Avoid using callable(). Callable() is not included in Python 3.1, so we shouldn't use it. --- diff --git a/requests/models.py b/requests/models.py index 9c0666a..3448335 100644 --- a/requests/models.py +++ b/requests/models.py @@ -9,6 +9,7 @@ This module contains the primary objects that power Requests. import os import socket +import collections from datetime import datetime from io import BytesIO @@ -467,10 +468,10 @@ class Request(object): def register_hook(self, event, hook): """Properly register a hook.""" - if callable(hook): + if isinstance(hook, collections.Callable): self.hooks[event].append(hook) elif hasattr(hook, '__iter__'): - self.hooks[event].extend(h for h in hook if callable(h)) + self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable)) def deregister_hook(self, event, hook): """Deregister a previously registered hook. diff --git a/tests/test_requests.py b/tests/test_requests.py index 6615678..22df526 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -11,6 +11,7 @@ import json import unittest import pickle import tempfile +import collections import requests from requests.compat import str, StringIO @@ -805,7 +806,7 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase): def assert_hooks_are_callable(hooks): for h in hooks['args']: - self.assertTrue(callable(h)) + self.assertTrue(isinstance(h, collections.Callable)) hooks = [add_foo_header, add_bar_header] r = requests.models.Request()