fix weird cases of using _isinstance instead of isinstance
This commit is contained in:
parent
35c4987b87
commit
edf1608cbb
@ -1770,9 +1770,7 @@ class CustomComponent(Component):
|
||||
return [
|
||||
Var(
|
||||
_js_expr=name,
|
||||
_var_type=(
|
||||
prop._var_type if types._isinstance(prop, Var) else type(prop)
|
||||
),
|
||||
_var_type=(prop._var_type if isinstance(prop, Var) else type(prop)),
|
||||
).guess_type()
|
||||
for name, prop in self.props.items()
|
||||
]
|
||||
|
@ -178,9 +178,9 @@ class Match(MemoizationLeaf):
|
||||
first_case_return = match_cases[0][-1]
|
||||
return_type = type(first_case_return)
|
||||
|
||||
if types._isinstance(first_case_return, BaseComponent):
|
||||
if isinstance(first_case_return, BaseComponent):
|
||||
return_type = BaseComponent
|
||||
elif types._isinstance(first_case_return, Var):
|
||||
elif isinstance(first_case_return, Var):
|
||||
return_type = Var
|
||||
|
||||
for index, case in enumerate(match_cases):
|
||||
@ -228,8 +228,8 @@ class Match(MemoizationLeaf):
|
||||
|
||||
# Validate the match cases (as well as the default case) to have Var return types.
|
||||
if any(
|
||||
case for case in match_cases if not types._isinstance(case[-1], Var)
|
||||
) or not types._isinstance(default, Var):
|
||||
case for case in match_cases if not isinstance(case[-1], Var)
|
||||
) or not isinstance(default, Var):
|
||||
raise ValueError("Return types of match cases should be Vars.")
|
||||
|
||||
return Var(
|
||||
|
@ -6,11 +6,10 @@ import dataclasses
|
||||
import textwrap
|
||||
from functools import lru_cache
|
||||
from hashlib import md5
|
||||
from typing import Any, Callable, Dict, Sequence, Union
|
||||
from typing import Any, Callable, Dict, Sequence
|
||||
|
||||
from reflex.components.component import BaseComponent, Component, CustomComponent
|
||||
from reflex.components.tags.tag import Tag
|
||||
from reflex.utils import types
|
||||
from reflex.utils.imports import ImportDict, ImportVar
|
||||
from reflex.vars.base import LiteralVar, Var
|
||||
from reflex.vars.function import ARRAY_ISARRAY, ArgsFunctionOperation, DestructuredArg
|
||||
@ -166,7 +165,7 @@ class Markdown(Component):
|
||||
Returns:
|
||||
The markdown component.
|
||||
"""
|
||||
if len(children) != 1 or not types._isinstance(children[0], Union[str, Var]):
|
||||
if len(children) != 1 or not isinstance(children[0], (str, Var)):
|
||||
raise ValueError(
|
||||
"Markdown component must have exactly one child containing the markdown source."
|
||||
)
|
||||
|
@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
from typing import Any, Dict, List, Optional, Sequence, Union
|
||||
from typing import Any, Dict, List, Mapping, Optional, Sequence
|
||||
|
||||
from reflex.event import EventChain
|
||||
from reflex.utils import format, types
|
||||
@ -103,7 +103,7 @@ class Tag:
|
||||
{
|
||||
format.to_camel_case(name, allow_hyphens=True): (
|
||||
prop
|
||||
if types._isinstance(prop, Union[EventChain, dict])
|
||||
if types._isinstance(prop, (EventChain, Mapping))
|
||||
else LiteralVar.create(prop)
|
||||
) # rx.color is always a string
|
||||
for name, prop in kwargs.items()
|
||||
|
@ -567,6 +567,11 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool:
|
||||
|
||||
from reflex.vars import LiteralVar, Var
|
||||
|
||||
if cls and is_union(cls):
|
||||
return any(_isinstance(obj, arg, nested=nested) for arg in get_args(cls))
|
||||
|
||||
if cls is Var:
|
||||
return isinstance(obj, Var)
|
||||
if isinstance(obj, LiteralVar):
|
||||
return _isinstance(obj._var_value, cls, nested=nested)
|
||||
if isinstance(obj, Var):
|
||||
@ -578,9 +583,6 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool:
|
||||
if is_literal(cls):
|
||||
return obj in get_args(cls)
|
||||
|
||||
if is_union(cls):
|
||||
return any(_isinstance(obj, arg, nested=nested) for arg in get_args(cls))
|
||||
|
||||
origin = get_origin(cls)
|
||||
|
||||
if origin is None:
|
||||
@ -758,7 +760,7 @@ def check_prop_in_allowed_types(prop: Any, allowed_types: Iterable) -> bool:
|
||||
"""
|
||||
from reflex.vars import Var
|
||||
|
||||
type_ = prop._var_type if _isinstance(prop, Var) else type(prop)
|
||||
type_ = prop._var_type if isinstance(prop, Var) else type(prop)
|
||||
return type_ in allowed_types
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user