experimental: do not show warning for internal imports

Only show experimental feature warnings when accessing the names through the
rx._x namespace.

If reflex internally imports the names via deep imports, then this bypasses the
warning to avoid showing it to users that have no control over how the
framework uses experimental features.
This commit is contained in:
Masen Furer 2025-01-30 16:03:08 -08:00
parent 98fb2d5e2a
commit 44ce7d134c
No known key found for this signature in database
GPG Key ID: 2AE2BD5531FF94F4

View File

@ -13,16 +13,25 @@ from .client_state import ClientStateVar as ClientStateVar
from .layout import layout as layout
from .misc import run_in_thread as run_in_thread
warn(
"`rx._x` contains experimental features and might be removed at any time in the future .",
)
_EMITTED_PROMOTION_WARNINGS = set()
class ExperimentalNamespace(SimpleNamespace):
"""Namespace for experimental features."""
def __getattribute__(self, item):
"""Get attribute from the namespace.
Args:
item: attribute name.
Returns:
The attribute.
"""
warn(
"`rx._x` contains experimental features and might be removed at any time in the future .",
dedupe=True,
)
return super().__getattribute__(item)
@property
def toast(self):
"""Temporary property returning the toast namespace.
@ -55,9 +64,7 @@ class ExperimentalNamespace(SimpleNamespace):
Args:
component_name: name of the component.
"""
if component_name not in _EMITTED_PROMOTION_WARNINGS:
_EMITTED_PROMOTION_WARNINGS.add(component_name)
warn(f"`rx._x.{component_name}` was promoted to `rx.{component_name}`.")
warn(f"`rx._x.{component_name}` was promoted to `rx.{component_name}`.", dedupe=True)
_x = ExperimentalNamespace(