<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def optgroups(self, name, value, attrs=None):
 """Add empty option for clearable selects."""

        if not self.is_required and not self.allow_multiple_selected:
            self.choices = list(chain([('', '')], self.choices))
        return super(Select2Mixin, self).optgroups(name, value, attrs=attrs)