浏览代码

be more careful with issubclass use with var_type (#4951)

Khaleel Al-Adhami 2 月之前
父节点
当前提交
06c7ba4853
共有 3 个文件被更改,包括 12 次插入5 次删除
  1. 2 1
      reflex/components/radix/themes/components/slider.py
  2. 7 2
      reflex/event.py
  3. 3 2
      reflex/vars/number.py

+ 2 - 1
reflex/components/radix/themes/components/slider.py

@@ -7,6 +7,7 @@ from typing import Literal, Sequence
 from reflex.components.component import Component
 from reflex.components.core.breakpoints import Responsive
 from reflex.event import EventHandler, passthrough_event_spec
+from reflex.utils.types import typehint_issubclass
 from reflex.vars.base import Var
 
 from ..base import LiteralAccentColor, RadixThemesComponent
@@ -96,7 +97,7 @@ class Slider(RadixThemesComponent):
         width = props.pop("width", "100%")
 
         if isinstance(default_value, Var):
-            if issubclass(default_value._var_type, (int, float)):
+            if typehint_issubclass(default_value._var_type, int | float):
                 default_value = [default_value]
 
         elif isinstance(default_value, (int, float)):

+ 7 - 2
reflex/event.py

@@ -37,7 +37,12 @@ from reflex.utils.exceptions import (
     EventHandlerArgTypeMismatchError,
     MissingAnnotationError,
 )
-from reflex.utils.types import ArgsSpec, GenericType, typehint_issubclass
+from reflex.utils.types import (
+    ArgsSpec,
+    GenericType,
+    safe_issubclass,
+    typehint_issubclass,
+)
 from reflex.vars import VarData
 from reflex.vars.base import LiteralVar, Var
 from reflex.vars.function import (
@@ -424,7 +429,7 @@ class EventChain(EventActionsMixin):
                 return value
             elif isinstance(value, EventVar):
                 value = [value]
-            elif issubclass(value._var_type, (EventChain, EventSpec)):
+            elif safe_issubclass(value._var_type, (EventChain, EventSpec)):
                 return cls.create(
                     value=value.guess_type(),
                     args_spec=args_spec,

+ 3 - 2
reflex/vars/number.py

@@ -23,6 +23,7 @@ from reflex.utils.exceptions import (
     VarValueError,
 )
 from reflex.utils.imports import ImportDict, ImportVar
+from reflex.utils.types import safe_issubclass
 
 from .base import (
     CustomVarOperationReturn,
@@ -524,7 +525,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
         Returns:
             bool: True if the number is a float.
         """
-        return issubclass(self._var_type, float)
+        return safe_issubclass(self._var_type, float)
 
     def _is_strict_int(self) -> bool:
         """Check if the number is an int.
@@ -532,7 +533,7 @@ class NumberVar(Var[NUMBER_T], python_types=(int, float)):
         Returns:
             bool: True if the number is an int.
         """
-        return issubclass(self._var_type, int)
+        return safe_issubclass(self._var_type, int)
 
     def __format__(self, format_spec: str) -> str:
         """Format the number.