#27919: Decide if attrs (and possibly others) are named or positional
parameters in
new widget rendering code
-------------------------------------------+------------------------
Reporter: Claude Paroz | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Discussed on IRC:
{{{
claudep: in the new form widget rendering code, we often have attrs=None
in signatures, but then passed as positional argument in various calls
claudep: I wonder if this is a good practice
claudep: this can lead to some issues when overriding methods and useing
*args, or **kwargs
claudep: thoughts?
MarkusH: claudep: I didn't look at the code, but from what you say I can
imagine that leading to issues
}}}
A concrete example:
{{{
class CustomSelect(Select):
def create_option(self, name, value, label, selected, index,
attrs=None, **kwargs):
if 'somestring' in label:
if attrs is None:
attrs = {}
attrs['disabled'] = True
return super().create_option(name, value, label, selected, index,
attrs=attrs, **kwargs)
}}}
leads to
{{{
...
File ".../django/forms/widgets.py", line 671, in get_context
context = super(Select, self).get_context(name, value, attrs)
File ".../django/forms/widgets.py", line 627, in get_context
context['widget']['optgroups'] = self.optgroups(name,
context['widget']['value'], attrs)
File ".../django/forms/widgets.py", line 599, in optgroups
attrs=attrs,
TypeError: create_option() got multiple values for argument 'attrs'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27919>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.64039c5d13b81d37bdaed3a6cb55d86b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.