MCPcopy Create free account
hub / github.com/dot-agent/nextpy / format_state

Function format_state

nextpy/utils/format.py:525–554  ·  view source on GitHub ↗

Recursively format values in the given state. Args: value: The state to format. Returns: The formatted state. Raises: TypeError: If the given value is not a valid state.

(value: Any)

Source from the content-addressed store, hash-verified

523
524
525def format_state(value: Any) -> Any:
526 """Recursively format values in the given state.
527
528 Args:
529 value: The state to format.
530
531 Returns:
532 The formatted state.
533
534 Raises:
535 TypeError: If the given value is not a valid state.
536 """
537 # Handle dicts.
538 if isinstance(value, dict):
539 return {k: format_state(v) for k, v in value.items()}
540
541 # Handle lists, sets, typles.
542 if isinstance(value, types.StateIterBases):
543 return [format_state(v) for v in value]
544
545 # Return state vars as is.
546 if isinstance(value, types.StateBases):
547 return value
548
549 # Serialize the value.
550 serialized = serialize(value)
551 if serialized is not None:
552 return serialized
553
554 raise TypeError(f"No JSON serializer found for var {value} of type {type(value)}.")
555
556
557def format_state_name(state_name: str) -> str:

Callers

nothing calls this directly

Calls 2

serializeFunction · 0.90
itemsMethod · 0.80

Tested by

no test coverage detected