def METHOD_NAME(self, scope, action):
    def policy_active_for_realm(realm: str):
        # Note: This takes advantage of local variable scope
        policies = self._policy_eval.has_policy(
            {
                "realm": realm,
                "scope": scope,
                "action": action,
                "user": self._user,
                "active": True,
            },
            strict_matches=False,
        )
        return len(policies) > 0
    if policy_active_for_realm("*"):
        allowed_realms = ["*"]
        return allowed_realms
    allowed_realms = [
        realm
        for realm in self._all_realms
        if policy_active_for_realm(realm)
    ]
    return allowed_realms