Skip to content

Commit 06c7ba4

Browse files
authored
be more careful with issubclass use with var_type (#4951)
1 parent 1ac8f02 commit 06c7ba4

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

reflex/components/radix/themes/components/slider.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from reflex.components.component import Component
88
from reflex.components.core.breakpoints import Responsive
99
from reflex.event import EventHandler, passthrough_event_spec
10+
from reflex.utils.types import typehint_issubclass
1011
from reflex.vars.base import Var
1112

1213
from ..base import LiteralAccentColor, RadixThemesComponent
@@ -96,7 +97,7 @@ def create(
9697
width = props.pop("width", "100%")
9798

9899
if isinstance(default_value, Var):
99-
if issubclass(default_value._var_type, (int, float)):
100+
if typehint_issubclass(default_value._var_type, int | float):
100101
default_value = [default_value]
101102

102103
elif isinstance(default_value, (int, float)):

reflex/event.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@
3737
EventHandlerArgTypeMismatchError,
3838
MissingAnnotationError,
3939
)
40-
from reflex.utils.types import ArgsSpec, GenericType, typehint_issubclass
40+
from reflex.utils.types import (
41+
ArgsSpec,
42+
GenericType,
43+
safe_issubclass,
44+
typehint_issubclass,
45+
)
4146
from reflex.vars import VarData
4247
from reflex.vars.base import LiteralVar, Var
4348
from reflex.vars.function import (
@@ -424,7 +429,7 @@ def create(
424429
return value
425430
elif isinstance(value, EventVar):
426431
value = [value]
427-
elif issubclass(value._var_type, (EventChain, EventSpec)):
432+
elif safe_issubclass(value._var_type, (EventChain, EventSpec)):
428433
return cls.create(
429434
value=value.guess_type(),
430435
args_spec=args_spec,

reflex/vars/number.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
VarValueError,
2424
)
2525
from reflex.utils.imports import ImportDict, ImportVar
26+
from reflex.utils.types import safe_issubclass
2627

2728
from .base import (
2829
CustomVarOperationReturn,
@@ -524,15 +525,15 @@ def _is_strict_float(self) -> bool:
524525
Returns:
525526
bool: True if the number is a float.
526527
"""
527-
return issubclass(self._var_type, float)
528+
return safe_issubclass(self._var_type, float)
528529

529530
def _is_strict_int(self) -> bool:
530531
"""Check if the number is an int.
531532
532533
Returns:
533534
bool: True if the number is an int.
534535
"""
535-
return issubclass(self._var_type, int)
536+
return safe_issubclass(self._var_type, int)
536537

537538
def __format__(self, format_spec: str) -> str:
538539
"""Format the number.

0 commit comments

Comments
 (0)