def __setattr__(self, name: str, value: Any):
        """Set the attribute.

        If the attribute is inherited, set the attribute on the parent state.

        Args:
            name: The name of the attribute.
            value: The value of the attribute.

        Raises:
            SetUndefinedStateVarError: If a value of a var is set without first defining it.
        """
        if isinstance(value, MutableProxy):
            # unwrap proxy objects when assigning back to the state
            value = value.__wrapped__

        # Set the var on the parent state.
        if name in self.inherited_vars or name in self.inherited_backend_vars:
            setattr(self.parent_state, name, value)
            return

        if name in self.backend_vars:
            self._backend_vars.__setitem__(name, value)
            self.dirty_vars.add(name)
            self._mark_dirty()
            return

        if (
            name not in self.vars
            and name not in self.get_skip_vars()
            and not name.startswith("__")
            and not name.startswith(
                f"_{getattr(type(self), '__original_name__', type(self).__name__)}__"
            )
        ):
            msg = (
                f"The state variable '{name}' has not been defined in '{type(self).__name__}'. "
                f"All state variables must be declared before they can be set."
            )
            raise SetUndefinedStateVarError(msg)

        fields = self.get_fields()

        if (field := fields.get(name)) is not None and field.is_var:
            field_type = field.outer_type_
            if not _isinstance(value, field_type, nested=1, treat_var_as_type=False):
                console.error(
                    f"Expected field '{type(self).__name__}.{name}' to receive type '{escape(str(field_type))}',"
                    f" but got '{value}' of type '{type(value)}'."
                )

        # Set the attribute.
        object.__setattr__(self, name, value)

        # Add the var to the dirty list.
        if name in self.base_vars:
            self.dirty_vars.add(name)
            self._mark_dirty()

        # For now, handle router_data updates as a special case
        if name == constants.ROUTER_DATA:
            self.dirty_vars.add(name)
            self._mark_dirty()
Set the attribute.

        If the attribute is inherited, set the attribute on the parent state.

        Args:
            name: The name of the attribute.
            value: The value of the attribute.

        Raises:
            SetUndefinedStateVarError: If a value of a var is set without first defining it.
        
reflex/state.py