From 35045e851a75b23d3d4e50853dfc1c5555110895 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Mon, 20 Apr 2015 20:13:57 -0500 Subject: [PATCH] Simplify PreparedRequest.prepare API Do not require that hooks be passed as an empty list to PreparedRequest.prepare. In the event hooks is None in prepare or prepare_hooks, use an empty list as a default. Related to #2552 --- requests/models.py | 4 ++++ test_requests.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 752c58c153..45b3ea9680 100644 --- a/requests/models.py +++ b/requests/models.py @@ -523,6 +523,10 @@ def prepare_cookies(self, cookies): def prepare_hooks(self, hooks): """Prepares the given hooks.""" + # hooks can be passed as None to the prepare method and to this + # method. To prevent iterating over None, simply use an empty list + # if hooks is False-y + hooks = hooks or [] for event in hooks: self.register_hook(event, hooks[event]) diff --git a/test_requests.py b/test_requests.py index 15406a22fc..cad8c055c8 100755 --- a/test_requests.py +++ b/test_requests.py @@ -1613,7 +1613,6 @@ def test_prepare_unicode_url(): p.prepare( method='GET', url=u('http://www.example.com/üniçø∂é'), - hooks=[] ) assert_copy(p, p.copy())