handle mapping as dict in type hint
This commit is contained in:
parent
a1b31b4baf
commit
35c4987b87
@ -191,10 +191,6 @@ def satisfies_type_hint(obj: Any, type_hint: Any) -> bool:
|
|||||||
Returns:
|
Returns:
|
||||||
Whether the object satisfies the type hint.
|
Whether the object satisfies the type hint.
|
||||||
"""
|
"""
|
||||||
if isinstance(obj, LiteralVar):
|
|
||||||
return types._isinstance(obj._var_value, type_hint, nested=1)
|
|
||||||
if isinstance(obj, Var):
|
|
||||||
return types._issubclass(obj._var_type, type_hint)
|
|
||||||
return types._isinstance(obj, type_hint, nested=1)
|
return types._isinstance(obj, type_hint, nested=1)
|
||||||
|
|
||||||
|
|
||||||
@ -711,6 +707,9 @@ class Component(BaseComponent, ABC):
|
|||||||
if isinstance(child, (tuple, list)):
|
if isinstance(child, (tuple, list)):
|
||||||
validate_children(child)
|
validate_children(child)
|
||||||
|
|
||||||
|
if isinstance(child, Var):
|
||||||
|
continue
|
||||||
|
|
||||||
# Make sure the child is a valid type.
|
# Make sure the child is a valid type.
|
||||||
if isinstance(child, dict) or not types._isinstance(
|
if isinstance(child, dict) or not types._isinstance(
|
||||||
child, ComponentChild
|
child, ComponentChild
|
||||||
|
@ -565,6 +565,13 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool:
|
|||||||
if cls is Any:
|
if cls is Any:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
from reflex.vars import LiteralVar, Var
|
||||||
|
|
||||||
|
if isinstance(obj, LiteralVar):
|
||||||
|
return _isinstance(obj._var_value, cls, nested=nested)
|
||||||
|
if isinstance(obj, Var):
|
||||||
|
return _issubclass(obj._var_type, cls)
|
||||||
|
|
||||||
if cls is None or cls is type(None):
|
if cls is None or cls is type(None):
|
||||||
return obj is None
|
return obj is None
|
||||||
|
|
||||||
@ -614,8 +621,8 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool:
|
|||||||
for item, arg in zip(obj, args, strict=True)
|
for item, arg in zip(obj, args, strict=True)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if origin in (dict, Breakpoints):
|
if origin in (dict, Mapping, Breakpoints):
|
||||||
return isinstance(obj, dict) and all(
|
return isinstance(obj, Mapping) and all(
|
||||||
_isinstance(key, args[0], nested=nested - 1)
|
_isinstance(key, args[0], nested=nested - 1)
|
||||||
and _isinstance(value, args[1], nested=nested - 1)
|
and _isinstance(value, args[1], nested=nested - 1)
|
||||||
for key, value in obj.items()
|
for key, value in obj.items()
|
||||||
|
Loading…
Reference in New Issue
Block a user