1
0

proxy.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. """A module to hold state proxy classes."""
  2. from typing import Any
  3. from reflex.state import StateProxy
  4. class ReadOnlyStateProxy(StateProxy):
  5. """A read-only proxy for a state."""
  6. def __setattr__(self, name: str, value: Any) -> None:
  7. """Prevent setting attributes on the state for read-only proxy.
  8. Args:
  9. name: The attribute name.
  10. value: The attribute value.
  11. Raises:
  12. NotImplementedError: Always raised when trying to set an attribute on proxied state.
  13. """
  14. if name.startswith("_self_"):
  15. # Special case attributes of the proxy itself, not applied to the wrapped object.
  16. super().__setattr__(name, value)
  17. return
  18. raise NotImplementedError("This is a read-only state proxy.")
  19. def mark_dirty(self):
  20. """Mark the state as dirty.
  21. Raises:
  22. NotImplementedError: Always raised when trying to mark the proxied state as dirty.
  23. """
  24. raise NotImplementedError("This is a read-only state proxy.")