Allow datagrid Column subclasses to set attributes on the class level.

Review Request #14824 — Created Feb. 17, 2026 and updated

Information

Djblets
release-5.x

Reviewers

Historically, Column subclasses had to override __init__ and set
attributes there. This was a bit messy and error-prone, as it was common
to mix up positional and keyword arguments when subclassing, and made
for harder customization for more complex class hierarchies.

Now, subclasses can set these arguments directly on the class as
attributes. The base Column class has defaults for all these fields,
which can be overridden by subclasses and further overridden when
calling __init__(). Built-in subclasses also provide their own fitting
this pattern.

To make this work, the arguments in __init__() are all set to UNSET
by default. If UNSET, class attributes (or more complex default
calculations) are used, but if any value is explicitly provided, it will
be used instead.

To help avoid the mess of positional and keyword arguments in these
classes, all arguments other than label are now keyword-only, with
positional arguments deprecated and scheduled for removal in Djblets 7.

This is now the recommended approach for column subclasses. It has the
benefit of storing less state per-instance, as well, as we only set the
values on the instance if they're explicitly provided during
construction.

Unit tests pass.

Tested updating existing columns to use this, and verified the new
settings were correct.

Summary ID
Allow datagrid Column subclasses to set attributes on the class level.
Historically, `Column` subclasses had to override `__init__` and set attributes there. This was a bit messy and error-prone, as it was common to mix up positional and keyword arguments when subclassing, and made for harder customization for more complex class hierarchies. Now, subclasses can set these arguments directly on the class as attributes. The base `Column` class has defaults for all these fields, which can be overridden by subclasses and further overridden when calling `__init__()`. Built-in subclasses also provide their own fitting this pattern. To make this work, the arguments in `__init__()` are all set to `UNSET` by default. If `UNSET`, class attributes (or more complex default calculations) are used, but if any value is explicitly provided, it will be used instead. To help avoid the mess of positional and keyword arguments in these classes, all arguments other than `label` are now keyword-only, with positional arguments deprecated and scheduled for removal in Djblets 7. This is now the recommended approach for column subclasses. It has the benefit of storing less state per-instance, as well, as we only set the values on the instance if they're explicitly provided during construction.
2fa0467921ab882e082fc04cad1e8c5d0d1495c0
Description From Last Updated

Should we do format_html(self.detailed_label) here to be safe?

maubinmaubin

Can you add a Raises section for this in the docstring.

maubinmaubin

How come we're setting this to False instead of using the cell_clickable arg?

maubinmaubin
Checks run (2 succeeded)
flake8 passed.
JSHint passed.
maubin
  1. 
      
  2. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    Should we do format_html(self.detailed_label) here to be safe?

  3. djblets/datagrid/grids.py (Diff revision 1)
     
     
     
     
     
    Show all issues

    Can you add a Raises section for this in the docstring.

  4. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    How come we're setting this to False instead of using the cell_clickable arg?

  5.