def unparse_scopes(parsed_scopes):
    """Turn a parsed_scopes dictionary back into an expanded scopes set"""
    expanded_scopes = set()
    for base, filters in parsed_scopes.items():
        if filters == Scope.ALL:
            expanded_scopes.add(base)
        else:
            for entity, names_list in filters.items():
                for name in names_list:
                    expanded_scopes.add(f'{base}!{entity}={name}')
    # return immutable frozenset because the result is cached
    return frozenset(expanded_scopes)
Turn a parsed_scopes dictionary back into an expanded scopes set
jupyterhub/scopes.py