Opened 18 years ago
Closed 18 years ago
#2899 closed defect (fixed)
[patch] data and error_dict should have defaults in django.forms.FormWrapper
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Tools | Version: | |
Severity: | minor | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In some occations it is useful for data
and error_dict
to have defaults in django.forms.FormWrapper
.
Attachments (2)
Change History (5)
by , 18 years ago
Attachment: | formwrapper_defaults.diff added |
---|
comment:1 by , 18 years ago
There's a problem with the patch, John: in Python, default values for parameters are evaluated when the function is created, not when it is executed. Your patch will result in all FormWrappers sharing the same default dictionaries. You should change it to something like:
def __init__(self, manipulator, data=None, error_dict=None, edit_inline=True): self.manipulator, self.data = manipulator, (data or {}) self.error_dict = error_dict or {}
by , 18 years ago
Attachment: | formwrapper_defaults.2.diff added |
---|
New version of [patch] with changes suggested by adurdin
comment:2 by , 18 years ago
The a or b thingy in Python is not good for default arguments. If you supply an empty dictionary as argument, it will be replaced silently with another object by the arg or {} expression. The failsafe approach is to manually test for None:
def f (arg=None): if arg is None: arg = {}
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch for ticket #2899