(Auto-) Hide indirect only view layers in viewport?

Dear all,

I was wondering if there is a way to preview view-/render layers in the viewport including collections that only contribute indirectly. While collections set to holdout are displayed as expected (invisible, but holding out “regular” collections), the indirect only option does not seem to make any difference in the viewport, neither in material preview mode nor in rendered mode. While I can disable the viewport visibility manually, I find this rather tedious when setting up multi layer setups.

ViewLayers

I have written a simple python snippet to achieve this, but wonder if I am missing a more obvious solution to this.

import bpy

def hide_indirect(l_col):
    if len(l_col.children) > 0:
        for child in l_col.children:
            child.hide_viewport =  child.indirect_only
            if not child.hide_viewport:
                l_col.hide_viewport = False
            hide_indirect(child)
            
hide_indirect(bpy.context.view_layer.layer_collection)

Thank you!

Edit: Typo