Skip to content

Convert a few usages of rx.base to dataclasses#1794

Merged
adhami3310 merged 4 commits intomainfrom
convert-a-few-usages-of-rx.Base-to-dataclasses
Mar 28, 2026
Merged

Convert a few usages of rx.base to dataclasses#1794
adhami3310 merged 4 commits intomainfrom
convert-a-few-usages-of-rx.Base-to-dataclasses

Conversation

@adhami3310
Copy link
Copy Markdown
Member

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR migrates data-holding classes from rx.Base (Reflex's Pydantic-backed base) to standard Python @dataclasses.dataclass, which is now the preferred pattern. Documentation examples and the sidebar SideBarBase helper class are updated consistently, and rx.Base is removed from the API-reference module list.\n\nKey changes:\n- docs/getting_started/dashboard_tutorial.md & docs/enterprise/drag-and-drop.md: All class Foo(rx.Base) occurrences replaced with @dataclasses.dataclass; exec blocks include the necessary import dataclasses.\n- pcweb/components/docpage/sidebar/state.py: SideBarBase converted to @dataclass(kw_only=True); mutable default children: list[SideBarItem] = [] correctly replaced with field(default_factory=list).\n- pcweb/pages/docs/apiref.py: rx.Base dropped from the modules list.\n- pcweb/pages/docs/component.py: Private rx.utils.types._issubclass replaced with a new safe_issubclass helper — but the replacement is inconsistent: render_select uses safe_issubclass while generate_props was changed to bare issubclass, which does not handle TypeError. A dead origin = get_origin(type_) assignment was also introduced immediately before it is unconditionally re-assigned.

Confidence Score: 4/5

Mostly safe; one P1 in generate_props where bare issubclass can throw TypeError for generic/non-class component types that the original _issubclass handled silently.

The documentation and sidebar changes are clean and correct. The P1 issue in component.py (issubclass vs safe_issubclass in generate_props) is a real potential runtime error on the component docs page. The dead origin assignment is cosmetic but shows the refactoring was not fully cleaned up.

pcweb/pages/docs/component.py — inconsistent issubclass guard and dead assignment.

Important Files Changed

Filename Overview
pcweb/pages/docs/component.py Replaces private rx.utils.types._issubclass with safe_issubclass helper and bare issubclass — inconsistently; also introduces a dead origin assignment overwritten immediately after.
pcweb/components/docpage/sidebar/state.py Converts SideBarBase from rx.Base to @dataclass(kw_only=True) with field(default_factory=list) for the mutable default — correct and clean.
pcweb/pages/docs/apiref.py Removes rx.Base from the API reference modules list, consistent with the migration away from rx.Base.
docs/getting_started/dashboard_tutorial.md Updates all rx.Base usages to @dataclasses.dataclass; exec blocks include the necessary import, static snippet blocks intentionally omit it as partial illustrations.
docs/enterprise/drag-and-drop.md Converts ListItem from rx.Base to @dataclasses.dataclass with import dataclasses added to the exec block.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[PropDocumentation / Component input] --> B[prop_docs]
    B --> C{safe_issubclass\nprop.type, rx.Var?}
    C -- Yes --> D[type_ = get_args type_ 0]
    C -- No --> E[keep type_]
    D --> F[origin = get_origin type_\nargs = get_args type_]
    E --> F

    G[generate_props] --> H{issubclass component\nRadixThemes / RadixPrimitive?}
    H -- TypeError possible --> I[unhandled TypeError\nno safe_issubclass guard]
    H -- No --> J[is_interactive = False]
    H -- Yes --> K[is_interactive = True]

    L[render_select] --> M{safe_issubclass component\nRadixThemes / RadixPrimitive?}
    M -- TypeError caught --> N[returns rx.fragment]
    M -- No --> O[returns rx.fragment]
    M -- Yes --> P[render select UI]
Loading

Reviews (1): Last reviewed commit: "precommit" | Re-trigger Greptile

@adhami3310 adhami3310 merged commit 4076c03 into main Mar 28, 2026
10 checks passed
@adhami3310 adhami3310 deleted the convert-a-few-usages-of-rx.Base-to-dataclasses branch March 28, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants