8000 Fixed #21740 -- Stopped using mutable default arguments in test client · alex-python/django@2a31d00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a31d00

Browse files
committed
Fixed #21740 -- Stopped using mutable default arguments in test client
Thanks Denver Coneybeare for the report and initial patch, and Atala for another patch.
1 parent a6e3fb8 commit 2a31d00

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

django/test/client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,29 +276,29 @@ def _get_path(self, parsed):
276276
path = path.encode('utf-8').decode('iso-8859-1')
277277
return path
278278

279-
def get(self, path, data={}, secure=False, **extra):
279+
def get(self, path, data=None, secure=False, **extra):
280280
"Construct a GET request."
281281

282282
r = {
283-
'QUERY_STRING': urlencode(data, doseq=True),
283+
'QUERY_STRING': urlencode(data or {}, doseq=True),
284284
}
285285
r.update(extra)
286286
return self.generic('GET', path, secure=secure, **r)
287287

288-
def post(self, path, data={}, content_type=MULTIPART_CONTENT,
288+
def post(self, path, data=None, content_type=MULTIPART_CONTENT,
289289
secure=False, **extra):
290290
"Construct a POST request."
291291

292-
post_data = self._encode_data(data, content_type)
292+
post_data = self._encode_data(data or {}, content_type)
293293

294294
return self.generic('POST', path, post_data, content_type,
295295
secure=secure, **extra)
296296

297-
def head(self, path, data={}, secure=False, **extra):
297+
def head(self, path, data=None, secure=False, **extra):
298298
"Construct a HEAD request."
299299

300300
r = {
301-
'QUERY_STRING': urlencode(data, doseq=True),
301+
'QUERY_STRING': urlencode(data or {}, doseq=True),
302302
}
303303
r.update(extra)
304304
return self.generic('HEAD', path, secure=secure, **r)
@@ -460,7 +460,7 @@ def request(self, **request):
460460
signals.template_rendered.disconnect(dispatch_uid=signal_uid)
461461
got_request_exception.disconnect(dispatch_uid="request-exception")
462462

463-
def get(self, path, data={}, follow=False, secure=False, **extra):
463+
def get(self, path, data=None, follow=False, secure=False, **extra):
464464
"""
465465
Requests a response from the server using GET.
466466
"""
@@ -470,7 +470,7 @@ def get(self, path, data={}, follow=False, secure=False, **extra):
470470
response = self._handle_redirects(response, **extra)
471471
return response
472472

473-
def post(self, path, data={}, content_type=MULTIPART_CONTENT,
473+
def post(self, path, data=None, content_type=MULTIPART_CONTENT,
474474
follow=False, secure=False, **extra):
475475
"""
476476
Requests a response from the server using POST.
@@ -482,7 +482,7 @@ def post(self, path, data={}, content_type=MULTIPART_CONTENT,
482482
response = self._handle_redirects(response, **extra)
483483
return response
484484

485-
def head(self, path, data={}, follow=False, secure=False, **extra):
485+
def head(self, path, data=None, follow=False, secure=False, **extra):
486486
"""
487487
Request a response from the server using HEAD.
488488
"""

docs/topics/testing/tools.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Use the ``django.test.Client`` class to make requests.
129129
Once you have a ``Client`` instance, you can call any of the following
130130
methods:
131131

132-
.. method:: Client.get(path, data={}, follow=False, secure=False, **extra)
132+
.. method:: Client.get(path, data=None, follow=False, secure=False, **extra)
133133

134134
.. versionadded:: 1.7
135135

@@ -192,7 +192,7 @@ Use the ``django.test.Client`` class to make requests.
192192
If you set ``secure`` to ``True`` the client will emulate an HTTPS
193193
request.
194194

195-
.. method:: Client.post(path, data={}, content_type=MULTIPART_CONTENT, follow=False, secure=False, **extra)
195+
.. method:: Client.post(path, data=None, content_type=MULTIPART_CONTENT, follow=False, secure=False, **extra)
196196

197197
Makes a POST request on the provided ``path`` and returns a
198198
``Response`` object, which is documented below.
@@ -269,7 +269,7 @@ Use the ``django.test.Client`` class to make requests.
269269
If you set ``secure`` to ``True`` the client will emulate an HTTPS
270270
request.
271271

272-
.. method:: Client.head(path, data={}, follow=False, secure=False, **extra)
272+
.. method:: Client.head(path, data=None, follow=False, secure=False, **extra)
273273

274274
Makes a HEAD request on the provided ``path`` and returns a
275275
``Response`` object. This method works just like :meth:`Client.get`,

0 commit comments

Comments
 (0)
0