#NEWLINE# @ dispatch ( ReLabel ) #NEWLINE# def _lean( expr , fields = None ) : #NEWLINE# #INDENT# labels = dict ( expr . labels ) #NEWLINE# reverse_labels = dict ( ( ( v , k ) for ( k , v ) in expr . labels ) ) #NEWLINE# child_fields = set ( ( reverse_labels . get ( f , fields ) for f in fields ) ) #NEWLINE# ( child , new_fields ) = _lean ( expr . _child , fields = child_fields ) #NEWLINE# return ( child . relabel ( ** dict ( ( ( k , v ) for ( k , v ) in expr . labels if ( k in child . fields ) ) ) ) , new_fields )