iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
803 stars 51 forks source link

Cannot set classes with a callable if the contain `__` in the classname. #579

Closed apollo13 closed 1 month ago

apollo13 commented 1 month ago

While trying to create a style for patternfly6 which uses class names like pf-v6-c-table__sort I ran into the issue that I cannot set this to a callable:

my_style = Style(
    base,
    Column=dict(
        header__attrs__class={
            "yolo": lambda **_: False,
            "bogo__sort": lambda **_: False,
        }
    ),
)

Attaching that style to a table yields: class="bogo__sort first_column iommi_sort_header subheader". The problem seems to be that iommi.attrs.render_class doesn't evaluate the callable. Inserting

print(items(flatten(class_dict)))

into that function yields:

dict_items([('sorted', False), ('descending', False), ('ascending', False), ('first_column', True), ('subheader', True), ('iommi_sort_header', True), ('yolo', False), ('bogo__sort', <function <lambda> at 0x7fbd89d62a20>)])

yolo apparently got evaluated higher up the chain already.

boxed commented 1 month ago

Fixed in #581