titus.genpy.cast

titus.genpy.cast(state, scope, expr, fromType, cases, partial, parser)[source]

Helper function for type-safe casting as an expression.

Parameters:
  • state (titus.genpy.ExecutionState) – exeuction state
  • scope (titus.util.DynamicScope) – dynamic scope object
  • expr (evaluated expression) – object to cast
  • fromType (string) – JSON-serialized Avro type
  • cases (list of (string, string, callable) triples) – list of (new variable for one case, JSON-serialized subtype, function to call if type matches) triples
  • partial (boolean) – if True, allow the set of cases to incompletely cover the fromType
  • parser (titus.datatype.ForwardDeclarationParser) – used to interpret fromType
Return type:

None or result of one of the cases callable

Returns:

if partial, returns None, else returns the result of the matching case