Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Eliminated lots of mutable default arguments (since they are bugs

waiting to happen and are memory leaks too).


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3070 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9b86db9bf2407f408468566b3f48a8444cb66f83 1 parent 88d215f
Luke Plant authored June 03, 2006
8  django/contrib/admin/utils.py
@@ -81,12 +81,16 @@ def parse_rst(text, default_reference_context, thing_being_parsed=None, link_bas
81 81
 }
82 82
 
83 83
 def create_reference_role(rolename, urlbase):
84  
-    def _role(name, rawtext, text, lineno, inliner, options={}, content=[]):
  84
+    def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
  85
+        if options is None: options = {}
  86
+        if content is None: content = []
85 87
         node = docutils.nodes.reference(rawtext, text, refuri=(urlbase % (inliner.document.settings.link_base, text.lower())), **options)
86 88
         return [node], []
87 89
     docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
88 90
 
89  
-def default_reference_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
  91
+def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None):
  92
+    if options is None: options = {}
  93
+    if content is None: content = []
90 94
     context = inliner.document.settings.default_reference_context
91 95
     node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
92 96
     return [node], []
4  django/contrib/admin/views/main.py
@@ -579,7 +579,9 @@ def get_filters(self, request):
579 579
                     filter_specs.append(spec)
580 580
         return filter_specs, bool(filter_specs)
581 581
 
582  
-    def get_query_string(self, new_params={}, remove=[]):
  582
+    def get_query_string(self, new_params=None, remove=None):
  583
+        if new_params is None: new_params = {}
  584
+        if remove is None: remove = []
583 585
         p = self.params.copy()
584 586
         for r in remove:
585 587
             for k in p.keys():
3  django/core/validators.py
@@ -399,7 +399,8 @@ class AnyValidator:
399 399
     as a validation error. The message is rather unspecific, so it's best to
400 400
     specify one on instantiation.
401 401
     """
402  
-    def __init__(self, validator_list=[], error_message=gettext_lazy("This field is invalid.")):
  402
+    def __init__(self, validator_list=None, error_message=gettext_lazy("This field is invalid.")):
  403
+        if validator_list is None: validator_list = []
403 404
         self.validator_list = validator_list
404 405
         self.error_message = error_message
405 406
         for v in validator_list:
6  django/db/backends/oracle/base.py
@@ -65,11 +65,13 @@ class FormatStylePlaceholderCursor(Database.Cursor):
65 65
     This fixes it -- but note that if you want to use a literal "%s" in a query,
66 66
     you'll need to use "%%s".
67 67
     """
68  
-    def execute(self, query, params=[]):
  68
+    def execute(self, query, params=None):
  69
+        if params is None: params = []
69 70
         query = self.convert_arguments(query, len(params))
70 71
         return Database.Cursor.execute(self, query, params)
71 72
 
72  
-    def executemany(self, query, params=[]):
  73
+    def executemany(self, query, params=None):
  74
+        if params is None: params = []
73 75
         query = self.convert_arguments(query, len(params[0]))
74 76
         return Database.Cursor.executemany(self, query, params)
75 77
 
71  django/forms/__init__.py
@@ -367,7 +367,8 @@ def get_id(self):
367 367
 
368 368
 class TextField(FormField):
369 369
     input_type = "text"
370  
-    def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=[], member_name=None):
  370
+    def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None):
  371
+        if validator_list is None: validator_list = []
371 372
         self.field_name = field_name
372 373
         self.length, self.maxlength = length, maxlength
373 374
         self.is_required = is_required
@@ -404,7 +405,8 @@ class PasswordField(TextField):
404 405
     input_type = "password"
405 406
 
406 407
 class LargeTextField(TextField):
407  
-    def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=[], maxlength=None):
  408
+    def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None):
  409
+        if validator_list is None: validator_list = []
408 410
         self.field_name = field_name
409 411
         self.rows, self.cols, self.is_required = rows, cols, is_required
410 412
         self.validator_list = validator_list[:]
@@ -422,7 +424,8 @@ def render(self, data):
422 424
             self.field_name, self.rows, self.cols, escape(data))
423 425
 
424 426
 class HiddenField(FormField):
425  
-    def __init__(self, field_name, is_required=False, validator_list=[]):
  427
+    def __init__(self, field_name, is_required=False, validator_list=None):
  428
+        if validator_list is None: validator_list = []
426 429
         self.field_name, self.is_required = field_name, is_required
427 430
         self.validator_list = validator_list[:]
428 431
 
@@ -452,7 +455,9 @@ def html2python(data):
452 455
     html2python = staticmethod(html2python)
453 456
 
454 457
 class SelectField(FormField):
455  
-    def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=[], member_name=None):
  458
+    def __init__(self, field_name, choices=None, size=1, is_required=False, validator_list=None, member_name=None):
  459
+        if validator_list is None: validator_list = []
  460
+        if choices is None: choices = []
456 461
         self.field_name = field_name
457 462
         # choices is a list of (value, human-readable key) tuples because order matters
458 463
         self.choices, self.size, self.is_required = choices, size, is_required
@@ -488,7 +493,9 @@ def html2python(data):
488 493
     html2python = staticmethod(html2python)
489 494
 
490 495
 class RadioSelectField(FormField):
491  
-    def __init__(self, field_name, choices=[], ul_class='', is_required=False, validator_list=[], member_name=None):
  496
+    def __init__(self, field_name, choices=None, ul_class='', is_required=False, validator_list=None, member_name=None):
  497
+        if validator_list is None: validator_list = []
  498
+        if choices is None: choices = []
492 499
         self.field_name = field_name
493 500
         # choices is a list of (value, human-readable key) tuples because order matters
494 501
         self.choices, self.is_required = choices, is_required
@@ -552,7 +559,8 @@ def isValidChoice(self, data, form):
552 559
 
553 560
 class NullBooleanField(SelectField):
554 561
     "This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None"
555  
-    def __init__(self, field_name, is_required=False, validator_list=[]):
  562
+    def __init__(self, field_name, is_required=False, validator_list=None):
  563
+        if validator_list is None: validator_list = []
556 564
         SelectField.__init__(self, field_name, choices=[('1', 'Unknown'), ('2', 'Yes'), ('3', 'No')],
557 565
             is_required=is_required, validator_list=validator_list)
558 566
 
@@ -605,7 +613,9 @@ class CheckboxSelectMultipleField(SelectMultipleField):
605 613
     back into the single list that validators, renderers and save() expect.
606 614
     """
607 615
     requires_data_list = True
608  
-    def __init__(self, field_name, choices=[], validator_list=[]):
  616
+    def __init__(self, field_name, choices=None, validator_list=None):
  617
+        if validator_list is None: validator_list = []
  618
+        if choices is None: choices = []
609 619
         SelectMultipleField.__init__(self, field_name, choices, size=1, is_required=False, validator_list=validator_list)
610 620
 
611 621
     def prepare(self, new_data):
@@ -636,7 +646,8 @@ def render(self, data):
636 646
 ####################
637 647
 
638 648
 class FileUploadField(FormField):
639  
-    def __init__(self, field_name, is_required=False, validator_list=[]):
  649
+    def __init__(self, field_name, is_required=False, validator_list=None):
  650
+        if validator_list is None: validator_list = []
640 651
         self.field_name, self.is_required = field_name, is_required
641 652
         self.validator_list = [self.isNonEmptyFile] + validator_list
642 653
 
@@ -675,7 +686,8 @@ def isValidImage(self, field_data, all_data):
675 686
 ####################
676 687
 
677 688
 class IntegerField(TextField):
678  
-    def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[], member_name=None):
  689
+    def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None):
  690
+        if validator_list is None: validator_list = []
679 691
         validator_list = [self.isInteger] + validator_list
680 692
         if member_name is not None:
681 693
             self.member_name = member_name
@@ -694,7 +706,8 @@ def html2python(data):
694 706
     html2python = staticmethod(html2python)
695 707
 
696 708
 class SmallIntegerField(IntegerField):
697  
-    def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=[]):
  709
+    def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None):
  710
+        if validator_list is None: validator_list = []
698 711
         validator_list = [self.isSmallInteger] + validator_list
699 712
         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
700 713
 
@@ -703,7 +716,8 @@ def isSmallInteger(self, field_data, all_data):
703 716
             raise validators.CriticalValidationError, gettext("Enter a whole number between -32,768 and 32,767.")
704 717
 
705 718
 class PositiveIntegerField(IntegerField):
706  
-    def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[]):
  719
+    def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None):
  720
+        if validator_list is None: validator_list = []
707 721
         validator_list = [self.isPositive] + validator_list
708 722
         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
709 723
 
@@ -712,7 +726,8 @@ def isPositive(self, field_data, all_data):
712 726
             raise validators.CriticalValidationError, gettext("Enter a positive number.")
713 727
 
714 728
 class PositiveSmallIntegerField(IntegerField):
715  
-    def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=[]):
  729
+    def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None):
  730
+        if validator_list is None: validator_list = []
716 731
         validator_list = [self.isPositiveSmall] + validator_list
717 732
         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
718 733
 
@@ -721,7 +736,8 @@ def isPositiveSmall(self, field_data, all_data):
721 736
             raise validators.CriticalValidationError, gettext("Enter a whole number between 0 and 32,767.")
722 737
 
723 738
 class FloatField(TextField):
724  
-    def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]):
  739
+    def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=None):
  740
+        if validator_list is None: validator_list = []
725 741
         self.max_digits, self.decimal_places = max_digits, decimal_places
726 742
         validator_list = [self.isValidFloat] + validator_list
727 743
         TextField.__init__(self, field_name, max_digits+1, max_digits+1, is_required, validator_list)
@@ -746,7 +762,8 @@ def html2python(data):
746 762
 class DatetimeField(TextField):
747 763
     """A FormField that automatically converts its data to a datetime.datetime object.
748 764
     The data should be in the format YYYY-MM-DD HH:MM:SS."""
749  
-    def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=[]):
  765
+    def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None):
  766
+        if validator_list is None: validator_list = []
750 767
         self.field_name = field_name
751 768
         self.length, self.maxlength = length, maxlength
752 769
         self.is_required = is_required
@@ -769,7 +786,8 @@ def html2python(data):
769 786
 class DateField(TextField):
770 787
     """A FormField that automatically converts its data to a datetime.date object.
771 788
     The data should be in the format YYYY-MM-DD."""
772  
-    def __init__(self, field_name, is_required=False, validator_list=[]):
  789
+    def __init__(self, field_name, is_required=False, validator_list=None):
  790
+        if validator_list is None: validator_list = []
773 791
         validator_list = [self.isValidDate] + validator_list
774 792
         TextField.__init__(self, field_name, length=10, maxlength=10,
775 793
             is_required=is_required, validator_list=validator_list)
@@ -793,7 +811,8 @@ def html2python(data):
793 811
 class TimeField(TextField):
794 812
     """A FormField that automatically converts its data to a datetime.time object.
795 813
     The data should be in the format HH:MM:SS or HH:MM:SS.mmmmmm."""
796  
-    def __init__(self, field_name, is_required=False, validator_list=[]):
  814
+    def __init__(self, field_name, is_required=False, validator_list=None):
  815
+        if validator_list is None: validator_list = []
797 816
         validator_list = [self.isValidTime] + validator_list
798 817
         TextField.__init__(self, field_name, length=8, maxlength=8,
799 818
             is_required=is_required, validator_list=validator_list)
@@ -827,7 +846,8 @@ def html2python(data):
827 846
 
828 847
 class EmailField(TextField):
829 848
     "A convenience FormField for validating e-mail addresses"
830  
-    def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=[]):
  849
+    def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None):
  850
+        if validator_list is None: validator_list = []
831 851
         validator_list = [self.isValidEmail] + validator_list
832 852
         TextField.__init__(self, field_name, length, maxlength=maxlength,
833 853
             is_required=is_required, validator_list=validator_list)
@@ -840,7 +860,8 @@ def isValidEmail(self, field_data, all_data):
840 860
 
841 861
 class URLField(TextField):
842 862
     "A convenience FormField for validating URLs"
843  
-    def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=[]):
  863
+    def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=None):
  864
+        if validator_list is None: validator_list = []
844 865
         validator_list = [self.isValidURL] + validator_list
845 866
         TextField.__init__(self, field_name, length=length, maxlength=maxlength,
846 867
             is_required=is_required, validator_list=validator_list)
@@ -852,7 +873,8 @@ def isValidURL(self, field_data, all_data):
852 873
             raise validators.CriticalValidationError, e.messages
853 874
 
854 875
 class IPAddressField(TextField):
855  
-    def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=[]):
  876
+    def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None):
  877
+        if validator_list is None: validator_list = []
856 878
         validator_list = [self.isValidIPAddress] + validator_list
857 879
         TextField.__init__(self, field_name, length=length, maxlength=maxlength,
858 880
             is_required=is_required, validator_list=validator_list)
@@ -873,7 +895,7 @@ def html2python(data):
873 895
 
874 896
 class FilePathField(SelectField):
875 897
     "A SelectField whose choices are the files in a given directory."
876  
-    def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=[]):
  898
+    def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None):
877 899
         import os
878 900
         if match is not None:
879 901
             import re
@@ -896,7 +918,8 @@ def __init__(self, field_name, path, match=None, recursive=False, is_required=Fa
896 918
 
897 919
 class PhoneNumberField(TextField):
898 920
     "A convenience FormField for validating phone numbers (e.g. '630-555-1234')"
899  
-    def __init__(self, field_name, is_required=False, validator_list=[]):
  921
+    def __init__(self, field_name, is_required=False, validator_list=None):
  922
+        if validator_list is None: validator_list = []
900 923
         validator_list = [self.isValidPhone] + validator_list
901 924
         TextField.__init__(self, field_name, length=12, maxlength=12,
902 925
             is_required=is_required, validator_list=validator_list)
@@ -909,7 +932,8 @@ def isValidPhone(self, field_data, all_data):
909 932
 
910 933
 class USStateField(TextField):
911 934
     "A convenience FormField for validating U.S. states (e.g. 'IL')"
912  
-    def __init__(self, field_name, is_required=False, validator_list=[]):
  935
+    def __init__(self, field_name, is_required=False, validator_list=None):
  936
+        if validator_list is None: validator_list = []
913 937
         validator_list = [self.isValidUSState] + validator_list
914 938
         TextField.__init__(self, field_name, length=2, maxlength=2,
915 939
             is_required=is_required, validator_list=validator_list)
@@ -929,7 +953,8 @@ def html2python(data):
929 953
 
930 954
 class CommaSeparatedIntegerField(TextField):
931 955
     "A convenience FormField for validating comma-separated integer fields"
932  
-    def __init__(self, field_name, maxlength=None, is_required=False, validator_list=[]):
  956
+    def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None):
  957
+        if validator_list is None: validator_list = []
933 958
         validator_list = [self.isCommaSeparatedIntegerList] + validator_list
934 959
         TextField.__init__(self, field_name, length=20, maxlength=maxlength,
935 960
             is_required=is_required, validator_list=validator_list)
3  django/template/__init__.py
@@ -227,7 +227,8 @@ def __init__(self, tokens):
227 227
         for lib in builtins:
228 228
             self.add_library(lib)
229 229
 
230  
-    def parse(self, parse_until=[]):
  230
+    def parse(self, parse_until=None):
  231
+        if parse_until is None: parse_until = []
231 232
         nodelist = self.create_nodelist()
232 233
         while self.tokens:
233 234
             token = self.next_token()
5  django/utils/datastructures.py
@@ -42,7 +42,8 @@ def has_key(self, key):
42 42
 
43 43
 class SortedDict(dict):
44 44
     "A dictionary that keeps its keys in the order in which they're inserted."
45  
-    def __init__(self, data={}):
  45
+    def __init__(self, data=None):
  46
+        if data is None: data = {}
46 47
         dict.__init__(self, data)
47 48
         self.keyOrder = data.keys()
48 49
 
@@ -123,7 +124,7 @@ def __setitem__(self, key, value):
123 124
     def __copy__(self):
124 125
         return self.__class__(dict.items(self))
125 126
 
126  
-    def __deepcopy__(self, memo={}):
  127
+    def __deepcopy__(self, memo):
127 128
         import copy
128 129
         result = self.__class__()
129 130
         memo[id(self)] = result
3  django/utils/xmlutils.py
@@ -5,8 +5,9 @@
5 5
 from xml.sax.saxutils import XMLGenerator
6 6
 
7 7
 class SimplerXMLGenerator(XMLGenerator):
8  
-    def addQuickElement(self, name, contents=None, attrs={}):
  8
+    def addQuickElement(self, name, contents=None, attrs=None):
9 9
         "Convenience method for adding an element with no children"
  10
+        if attrs is None: attrs = {}
10 11
         self.startElement(name, attrs)
11 12
         if contents is not None:
12 13
             self.characters(contents)
9  django/views/generic/create_update.py
@@ -9,7 +9,7 @@
9 9
 from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
10 10
 
11 11
 def create_object(request, model, template_name=None,
12  
-        template_loader=loader, extra_context={}, post_save_redirect=None,
  12
+        template_loader=loader, extra_context=None, post_save_redirect=None,
13 13
         login_required=False, follow=None, context_processors=None):
14 14
     """
15 15
     Generic object-creation function.
@@ -19,6 +19,7 @@ def create_object(request, model, template_name=None,
19 19
         form
20 20
             the form wrapper for the object
21 21
     """
  22
+    if extra_context is None: extra_context = {}
22 23
     if login_required and request.user.is_anonymous():
23 24
         return redirect_to_login(request.path)
24 25
 
@@ -71,7 +72,7 @@ def create_object(request, model, template_name=None,
71 72
 
72 73
 def update_object(request, model, object_id=None, slug=None,
73 74
         slug_field=None, template_name=None, template_loader=loader,
74  
-        extra_context={}, post_save_redirect=None,
  75
+        extra_context=None, post_save_redirect=None,
75 76
         login_required=False, follow=None, context_processors=None,
76 77
         template_object_name='object'):
77 78
     """
@@ -84,6 +85,7 @@ def update_object(request, model, object_id=None, slug=None,
84 85
         object
85 86
             the original object being edited
86 87
     """
  88
+    if extra_context is None: extra_context = {}
87 89
     if login_required and request.user.is_anonymous():
88 90
         return redirect_to_login(request.path)
89 91
 
@@ -143,7 +145,7 @@ def update_object(request, model, object_id=None, slug=None,
143 145
 
144 146
 def delete_object(request, model, post_delete_redirect,
145 147
         object_id=None, slug=None, slug_field=None, template_name=None,
146  
-        template_loader=loader, extra_context={},
  148
+        template_loader=loader, extra_context=None,
147 149
         login_required=False, context_processors=None, template_object_name='object'):
148 150
     """
149 151
     Generic object-delete function.
@@ -157,6 +159,7 @@ def delete_object(request, model, post_delete_redirect,
157 159
         object
158 160
             the original object being deleted
159 161
     """
  162
+    if extra_context is None: extra_context = {}
160 163
     if login_required and request.user.is_anonymous():
161 164
         return redirect_to_login(request.path)
162 165
 
18  django/views/generic/date_based.py
@@ -6,7 +6,7 @@
6 6
 
7 7
 def archive_index(request, queryset, date_field, num_latest=15,
8 8
         template_name=None, template_loader=loader,
9  
-        extra_context={}, allow_empty=False, context_processors=None,
  9
+        extra_context=None, allow_empty=False, context_processors=None,
10 10
         mimetype=None):
11 11
     """
12 12
     Generic top-level archive of date-based objects.
@@ -18,6 +18,7 @@ def archive_index(request, queryset, date_field, num_latest=15,
18 18
         latest
19 19
             Latest N (defaults to 15) objects by date
20 20
     """
  21
+    if extra_context is None: extra_context = {}
21 22
     model = queryset.model
22 23
     queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
23 24
     date_list = queryset.dates(date_field, 'year')[::-1]
@@ -44,7 +45,7 @@ def archive_index(request, queryset, date_field, num_latest=15,
44 45
     return HttpResponse(t.render(c), mimetype=mimetype)
45 46
 
46 47
 def archive_year(request, year, queryset, date_field, template_name=None,
47  
-        template_loader=loader, extra_context={}, allow_empty=False,
  48
+        template_loader=loader, extra_context=None, allow_empty=False,
48 49
         context_processors=None, template_object_name='object', mimetype=None,
49 50
         make_object_list=False):
50 51
     """
@@ -60,6 +61,7 @@ def archive_year(request, year, queryset, date_field, template_name=None,
60 61
             List of objects published in the given month
61 62
             (Only available if make_object_list argument is True)
62 63
     """
  64
+    if extra_context is None: extra_context = {}
63 65
     model = queryset.model
64 66
     now = datetime.datetime.now()
65 67
 
@@ -92,7 +94,7 @@ def archive_year(request, year, queryset, date_field, template_name=None,
92 94
 
93 95
 def archive_month(request, year, month, queryset, date_field,
94 96
         month_format='%b', template_name=None, template_loader=loader,
95  
-        extra_context={}, allow_empty=False, context_processors=None,
  97
+        extra_context=None, allow_empty=False, context_processors=None,
96 98
         template_object_name='object', mimetype=None):
97 99
     """
98 100
     Generic monthly archive view.
@@ -108,6 +110,7 @@ def archive_month(request, year, month, queryset, date_field,
108 110
         object_list:
109 111
             list of objects published in the given month
110 112
     """
  113
+    if extra_context is None: extra_context = {}
111 114
     try:
112 115
         date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3])
113 116
     except ValueError:
@@ -148,7 +151,7 @@ def archive_month(request, year, month, queryset, date_field,
148 151
 
149 152
 def archive_week(request, year, week, queryset, date_field,
150 153
         template_name=None, template_loader=loader,
151  
-        extra_context={}, allow_empty=True, context_processors=None,
  154
+        extra_context=None, allow_empty=True, context_processors=None,
152 155
         template_object_name='object', mimetype=None):
153 156
     """
154 157
     Generic weekly archive view.
@@ -160,6 +163,7 @@ def archive_week(request, year, week, queryset, date_field,
160 163
         object_list:
161 164
             list of objects published in the given week
162 165
     """
  166
+    if extra_context is None: extra_context = {}
163 167
     try:
164 168
         date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%U')[:3])
165 169
     except ValueError:
@@ -195,7 +199,7 @@ def archive_week(request, year, week, queryset, date_field,
195 199
 
196 200
 def archive_day(request, year, month, day, queryset, date_field,
197 201
         month_format='%b', day_format='%d', template_name=None,
198  
-        template_loader=loader, extra_context={}, allow_empty=False,
  202
+        template_loader=loader, extra_context=None, allow_empty=False,
199 203
         context_processors=None, template_object_name='object',
200 204
         mimetype=None):
201 205
     """
@@ -212,6 +216,7 @@ def archive_day(request, year, month, day, queryset, date_field,
212 216
         next_day
213 217
             (datetime) the next day, or None if the current day is today
214 218
     """
  219
+    if extra_context is None: extra_context = {}
215 220
     try:
216 221
         date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
217 222
     except ValueError:
@@ -261,7 +266,7 @@ def archive_today(request, **kwargs):
261 266
 def object_detail(request, year, month, day, queryset, date_field,
262 267
         month_format='%b', day_format='%d', object_id=None, slug=None,
263 268
         slug_field=None, template_name=None, template_name_field=None,
264  
-        template_loader=loader, extra_context={}, context_processors=None,
  269
+        template_loader=loader, extra_context=None, context_processors=None,
265 270
         template_object_name='object', mimetype=None):
266 271
     """
267 272
     Generic detail view from year/month/day/slug or year/month/day/id structure.
@@ -271,6 +276,7 @@ def object_detail(request, year, month, day, queryset, date_field,
271 276
         object:
272 277
             the object to be detailed
273 278
     """
  279
+    if extra_context is None: extra_context = {}
274 280
     try:
275 281
         date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
276 282
     except ValueError:
6  django/views/generic/list_detail.py
@@ -6,7 +6,7 @@
6 6
 
7 7
 def object_list(request, queryset, paginate_by=None, allow_empty=False,
8 8
         template_name=None, template_loader=loader,
9  
-        extra_context={}, context_processors=None, template_object_name='object',
  9
+        extra_context=None, context_processors=None, template_object_name='object',
10 10
         mimetype=None):
11 11
     """
12 12
     Generic list of objects.
@@ -34,6 +34,7 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
34 34
         hits
35 35
             number of objects, total
36 36
     """
  37
+    if extra_context is None: extra_context = {}
37 38
     queryset = queryset._clone()
38 39
     if paginate_by:
39 40
         paginator = ObjectPaginator(queryset, paginate_by)
@@ -78,7 +79,7 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
78 79
 
79 80
 def object_detail(request, queryset, object_id=None, slug=None,
80 81
         slug_field=None, template_name=None, template_name_field=None,
81  
-        template_loader=loader, extra_context={},
  82
+        template_loader=loader, extra_context=None,
82 83
         context_processors=None, template_object_name='object',
83 84
         mimetype=None):
84 85
     """
@@ -89,6 +90,7 @@ def object_detail(request, queryset, object_id=None, slug=None,
89 90
         object
90 91
             the object
91 92
     """
  93
+    if extra_context is None: extra_context = {}
92 94
     model = queryset.model
93 95
     if object_id:
94 96
         queryset = queryset.filter(pk=object_id)

0 notes on commit 9b86db9

Please sign in to comment.
Something went wrong with that request. Please try again.