def has_roles(var, roles, match_all=False):
 var_roles = getattr(var.tag, 'roles', [])
 matches = (any((isinstance(var_role, role.__class__) for var_role in var_roles)) for role in roles)
 return (all(matches) if match_all else any(matches))

def has_roles ( var , roles , match_all = False ) : var_roles = getattr ( var . tag , 'roles' , [ ] ) matches = ( any ( ( isinstance ( var_role , role . __class__ ) for var_role in var_roles ) ) for role in roles ) return ( all ( matches ) if match_all else any ( matches ) )
test if a variable has given roles taking subroles into account .