don't use _instance for simple unions

This commit is contained in:
Khaleel Al-Adhami 2025-02-05 11:24:18 -08:00
parent 374cd14862
commit 13a0efca4d
2 changed files with 4 additions and 5 deletions

View File

@ -179,6 +179,7 @@ ComponentStyle = Dict[
Union[str, Type[BaseComponent], Callable, ComponentNamespace], Any
]
ComponentChild = Union[types.PrimitiveType, Var, BaseComponent]
ComponentChildTypes = (*types.PrimitiveTypes, Var, BaseComponent)
def satisfies_type_hint(obj: Any, type_hint: Any) -> bool:
@ -707,12 +708,9 @@ class Component(BaseComponent, ABC):
if isinstance(child, (tuple, list)):
validate_children(child)
if isinstance(child, Var):
continue
# Make sure the child is a valid type.
if isinstance(child, dict) or not types._isinstance(
child, ComponentChild
if isinstance(child, dict) or not isinstance(
child, ComponentChildTypes
):
raise ChildrenTypeError(component=cls.__name__, child=child)

View File

@ -95,6 +95,7 @@ GenericType = Union[Type, _GenericAlias]
# Valid state var types.
JSONType = {str, int, float, bool}
PrimitiveType = Union[int, float, bool, str, list, dict, set, tuple]
PrimitiveTypes = (int, float, bool, str, list, dict, set, tuple)
StateVar = Union[PrimitiveType, Base, None]
StateIterVar = Union[list, set, tuple]