Hey Carlton,
in my opinion, the main use case would be to improve type safety, readability and to add a
utility class for 3rd party packages. Someday, Django may add type hints and then this would
be really beneficial.
In Django itself, the mentioned method
css_classes does not offer any type safety;
the passed in argument extra_classes can be None, a string containing a single
CSS class or list containing those classes.
By adding such a utility class, we can rewrite the above method to
css_classes(extra_classes: ClassList):
# optionally: extra_classes = ClassList(extra_classes)
extra_classes.toggle(getattr(self.form, "error_css_class", None), self.errors)
extra_classes.toggle(getattr(self.form, "required_css_class", None), self.field.required)
return extra_classes
which is much easier to read.
In my project
django-formset, I was able to remove a lot of boilerplate, by introducing that class.
Naming that Python class ClassSet or CSSClassSet or CSSClasses might be a better option.
I used ClassList because that's the name in JavaScript.
– Jacob