From 44ce7d134cd03fb65ab18e38a10b34488031cf24 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 30 Jan 2025 16:03:08 -0800 Subject: [PATCH] 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. --- reflex/experimental/__init__.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/reflex/experimental/__init__.py b/reflex/experimental/__init__.py index 1a198f35a..ffba14ff5 100644 --- a/reflex/experimental/__init__.py +++ b/reflex/experimental/__init__.py @@ -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(