Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF-3597]Type check Radio items #3856

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions reflex/components/radix/themes/components/radio_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from reflex.event import EventHandler
from reflex.ivars.base import ImmutableVar, LiteralVar
from reflex.ivars.sequence import StringVar
from reflex.utils import types
from reflex.vars import Var

from ..base import (
Expand Down Expand Up @@ -133,6 +134,9 @@ def create(

Returns:
The created radio group component.

Raises:
TypeError: If the type of items is invalid.
"""
direction = props.pop("direction", "column")
spacing = props.pop("spacing", "2")
Expand All @@ -141,6 +145,16 @@ def create(
color_scheme = props.pop("color_scheme", None)
default_value = props.pop("default_value", "")

if (
not isinstance(items, (list, Var))
or isinstance(items, Var)
and not types._issubclass(items._var_type, list)
):
items_type = type(items) if not isinstance(items, Var) else items._var_type
raise TypeError(
f"The radio group component takes in a list, got {items_type} instead"
)

default_value = LiteralVar.create(default_value)

# convert only non-strings to json(JSON.stringify) so quotes are not rendered
Expand Down
6 changes: 6 additions & 0 deletions reflex/components/radix/themes/components/radio_group.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ class HighLevelRadioGroup(RadixThemesComponent):

Returns:
The created radio group component.

Raises:
TypeError: If the type of items is invalid.
"""
...

Expand Down Expand Up @@ -588,6 +591,9 @@ class RadioGroup(ComponentNamespace):

Returns:
The created radio group component.

Raises:
TypeError: If the type of items is invalid.
"""
...

Expand Down
Loading