Added fix for serializing PIL images (#1619)
This commit is contained in:
parent
ed5727328e
commit
0be5d670ed
@ -381,7 +381,7 @@ def format_image_data(value: Type) -> str:
|
|||||||
return f"data:image/png;base64,{base64_image}"
|
return f"data:image/png;base64,{base64_image}"
|
||||||
|
|
||||||
|
|
||||||
def format_state(value: Any) -> Dict:
|
def format_state(value: Any) -> Any:
|
||||||
"""Recursively format values in the given state.
|
"""Recursively format values in the given state.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -397,6 +397,10 @@ def format_state(value: Any) -> Dict:
|
|||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
return {k: format_state(v) for k, v in value.items()}
|
return {k: format_state(v) for k, v in value.items()}
|
||||||
|
|
||||||
|
# Handle lists, sets, typles.
|
||||||
|
if isinstance(value, types.StateIterBases):
|
||||||
|
return [format_state(v) for v in value]
|
||||||
|
|
||||||
# Return state vars as is.
|
# Return state vars as is.
|
||||||
if isinstance(value, types.StateBases):
|
if isinstance(value, types.StateBases):
|
||||||
return value
|
return value
|
||||||
|
@ -14,6 +14,7 @@ GenericType = Union[Type, _GenericAlias]
|
|||||||
# Valid state var types.
|
# Valid state var types.
|
||||||
PrimitiveType = Union[int, float, bool, str, list, dict, set, tuple]
|
PrimitiveType = Union[int, float, bool, str, list, dict, set, tuple]
|
||||||
StateVar = Union[PrimitiveType, Base, None]
|
StateVar = Union[PrimitiveType, Base, None]
|
||||||
|
StateIterVar = Union[list, set, tuple]
|
||||||
|
|
||||||
|
|
||||||
def get_args(alias: _GenericAlias) -> Tuple[Type, ...]:
|
def get_args(alias: _GenericAlias) -> Tuple[Type, ...]:
|
||||||
@ -198,3 +199,4 @@ def is_backend_variable(name: str) -> bool:
|
|||||||
|
|
||||||
# Store this here for performance.
|
# Store this here for performance.
|
||||||
StateBases = get_base_class(StateVar)
|
StateBases = get_base_class(StateVar)
|
||||||
|
StateIterBases = get_base_class(StateIterVar)
|
||||||
|
Loading…
Reference in New Issue
Block a user