diff --git a/docs/enterprise/drag-and-drop.md b/docs/enterprise/drag-and-drop.md index 2bf8913d3..ee76470e6 100644 --- a/docs/enterprise/drag-and-drop.md +++ b/docs/enterprise/drag-and-drop.md @@ -216,10 +216,12 @@ def state_tracking_example(): Create dynamic draggable lists using `rx.foreach`: ```python demo exec +import dataclasses import reflex as rx import reflex_enterprise as rxe -class ListItem(rx.Base): +@dataclasses.dataclass +class ListItem: id: str text: str list_id: str diff --git a/docs/getting_started/dashboard_tutorial.md b/docs/getting_started/dashboard_tutorial.md index 7866cd409..d55c45009 100644 --- a/docs/getting_started/dashboard_tutorial.md +++ b/docs/getting_started/dashboard_tutorial.md @@ -27,9 +27,11 @@ You can see what the finished app and code will look like here: ```python exec +import dataclasses from collections import Counter -class User(rx.Base): +@dataclasses.dataclass +class User: """The user model.""" name: str @@ -181,7 +183,8 @@ rx.vstack( import reflex as rx from collections import Counter -class User(rx.Base): +@dataclasses.dataclass +class User: """The user model.""" name: str @@ -616,14 +619,15 @@ So far our data has been defined in a list of lists, where the data is accessed A better way to structure our data in Reflex is to use a class to represent a user. This way we can access the data using attributes i.e. `user.name`, `user.email`. -In Reflex when we create these classes to showcase our data, the class must inherit from `rx.Base`. - -`rx.Base` is also necessary if we want to have a state var that is an iterable with different types. For example if we wanted to have `age` as an `int` we would have to use `rx.base` as we could not do this with a state var defined as `list[list[str]]`. +In Reflex when we create these classes to showcase our data, we can use dataclasses. The `show_user` render function is also updated to access the data by named attributes, instead of indexing. ```python exec -class User(rx.Base): +import dataclasses + +@dataclasses.dataclass +class User: """The user model.""" name: str @@ -670,7 +674,8 @@ rx.table.root( ```python -class User(rx.Base): +@dataclasses.dataclass +class User: """The user model.""" name: str @@ -1119,7 +1124,8 @@ rx.vstack( ``` ```python -class User(rx.Base): +@dataclasses.dataclass +class User: """The user model.""" name: str @@ -1663,7 +1669,8 @@ rx.vstack( import reflex as rx from collections import Counter -class User(rx.Base): +@dataclasses.dataclass +class User: """The user model.""" name: str diff --git a/pcweb/components/docpage/sidebar/state.py b/pcweb/components/docpage/sidebar/state.py index a4831ea91..74cda741c 100644 --- a/pcweb/components/docpage/sidebar/state.py +++ b/pcweb/components/docpage/sidebar/state.py @@ -2,11 +2,13 @@ from __future__ import annotations +from dataclasses import dataclass, field + import reflex as rx -from reflex.base import Base -class SideBarBase(Base): +@dataclass(kw_only=True) +class SideBarBase: """Base class for the Side bar.""" # The name to display in the sidebar. @@ -18,7 +20,7 @@ class SideBarBase(Base): link: str = "" # The children items. - children: list[SideBarItem] = [] + children: list[SideBarItem] = field(default_factory=list) # Whether the item is a category. Occurs if a single item is at the top level of the sidebar for aesthetics. outer = False diff --git a/pcweb/pages/docs/apiref.py b/pcweb/pages/docs/apiref.py index ecb1f88e7..5ea2dbc03 100644 --- a/pcweb/pages/docs/apiref.py +++ b/pcweb/pages/docs/apiref.py @@ -8,7 +8,6 @@ modules = [ rx.App, - rx.Base, rx.Component, rx.ComponentState, (rx.Config, rx.config.BaseConfig), diff --git a/pcweb/pages/docs/component.py b/pcweb/pages/docs/component.py index b6ed123e1..807318bf4 100644 --- a/pcweb/pages/docs/component.py +++ b/pcweb/pages/docs/component.py @@ -78,14 +78,12 @@ class PropDocsState(rx.State): def render_select(prop: PropDocumentation, component: type[Component], prop_dict: dict): if ( - not rx.utils.types._issubclass( - component, (RadixThemesComponent, RadixPrimitiveComponent) - ) + not safe_issubclass(component, (RadixThemesComponent, RadixPrimitiveComponent)) or component.__name__ in EXCLUDED_COMPONENTS ): return rx.fragment() try: - type_ = rx.utils.types.get_args(prop.type)[0] + type_ = get_args(prop.type)[0] except Exception: return rx.fragment() @@ -249,6 +247,13 @@ def color_scheme_hovercard(literal_values: list[str]) -> rx.Component: ) +def safe_issubclass(cls, class_or_tuple): + try: + return issubclass(cls, class_or_tuple) + except TypeError: + return False + + def prop_docs( prop: PropDocumentation, prop_dict: dict, @@ -258,9 +263,10 @@ def prop_docs( """Generate the docs for a prop.""" # Get the type of the prop. type_ = prop.type - if rx.utils.types._issubclass(prop.type, rx.Var): + origin = get_origin(type_) + if safe_issubclass(origin, rx.Var): # For vars, get the type of the var. - type_ = rx.utils.types.get_args(type_)[0] + type_ = get_args(type_)[0] origin = get_origin(type_) args = get_args(type_) @@ -448,7 +454,7 @@ def generate_props( prop_dict = {} is_interactive = True - if not rx.utils.types._issubclass( + if not issubclass( component, (RadixThemesComponent, RadixPrimitiveComponent) ) or component.__name__ in [ "Theme", diff --git a/uv.lock b/uv.lock index d9bed5b7d..ee3bee985 100644 --- a/uv.lock +++ b/uv.lock @@ -2564,7 +2564,7 @@ dependencies = [ [[package]] name = "reflex-enterprise" -version = "0.6.4" +version = "0.6.5" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "asgiproxy" }, @@ -2573,9 +2573,9 @@ dependencies = [ { name = "psutil" }, { name = "reflex" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/2f/51/ef82746c384687d4c71f44be2294c40e4da0be35d546b45d5b14bd03203e/reflex_enterprise-0.6.4.tar.gz", hash = "sha256:1e84f97d9b4cf9a275304f164898cd9208c34176e5771b1765ea842c42611afb", size = 390702, upload-time = "2026-03-18T17:41:26.158Z" } +sdist = { url = "https://files.pythonhosted.org/packages/03/64/9e77e5a4cf021daab98468f8a9612af586793502b37e69c8f8d313a16121/reflex_enterprise-0.6.5.tar.gz", hash = "sha256:6d219e7a4a345cc6495a2a90c78a9eb34add3e58121f73534988f428af2c04a9", size = 390599, upload-time = "2026-03-27T19:40:46.814Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/5b/74/79533d03f79ca498893f9f98faa12084423a4c1af69a715d62ed394f95c8/reflex_enterprise-0.6.4-py3-none-any.whl", hash = "sha256:ac9dab9031872c4fe391d2e881a9306ce983c2cb7532a10711ac3c0fc0add9c2", size = 216259, upload-time = "2026-03-18T17:41:27.584Z" }, + { url = "https://files.pythonhosted.org/packages/ac/90/6e75bee88db1b84e750e4ff62a42839218eecf66d0129f8c87046836317c/reflex_enterprise-0.6.5-py3-none-any.whl", hash = "sha256:6aba8bd5becf73b5dccf3a90d14f4309d7da5003ebdf99d144fe8db9aa8cdec1", size = 216180, upload-time = "2026-03-27T19:40:48.155Z" }, ] [[package]]