Skip to main content

TypeTransformer

Base transformer type that should be implemented for every python native type that can be handled by flytekit

Constructors

  • Base transformer type that should be implemented for every python native type that can be handled by flytekit

  • Parameters

    • name: string
      • The name of the transformer.
    • t: Type[T]
      • The Python type that this transformer handles.
    • enable_type_assertions: bool
      • Whether to enable type assertions.

Methods

def name()
  • This returns the name of the transformer.

  • Return Value: string

    • The name of the transformer.
def python_type()
  • This returns the python type.

  • Return Value: Type[T]

    • The Python type being transformed.
def type_assertions_enabled()
  • Indicates if the transformer wants type assertions to be enabled at the core type engine layer

  • Return Value: bool

    • True if type assertions are enabled, False otherwise.
def isinstance_generic(obj: any, generic_alias: any) - > None
  • Checks if an object is an instance of a generic alias.

  • Parameters

    • obj: any
      • The object to check.
    • generic_alias: any
      • The generic alias to check against.
  • Return Value: None

    • None
def assert_type(t: Type[T], v: T) - > None
  • Asserts that a value is of the expected type.

  • Parameters

    • t: Type[T]
      • The expected type.
    • v: T
      • The value to assert.
  • Return Value: None

    • None
def get_literal_type(t: Type[T]) - > LiteralType
  • Converts the python type to a Flyte LiteralType.

  • Parameters

    • t: Type[T]
      • The Python type to convert.
  • Return Value: LiteralType

    • The Flyte LiteralType representation of the Python type.
def guess_python_type(literal_type: LiteralType) - > Type[T]
  • Converts the Flyte LiteralType to a python object type.

  • Parameters

    • literal_type: LiteralType
      • The Flyte LiteralType to convert.
  • Return Value: Type[T]

    • The Python type corresponding to the LiteralType.
def to_literal(python_val: T, python_type: Type[T], expected: LiteralType) - > Literal
  • Converts a given python_val to a Flyte Literal, assuming the given python_val matches the declared python_type. Implementers should refrain from using type(python_val) instead rely on the passed in python_type. If these do not match (or are not allowed) the Transformer implementer should raise an AssertionError, clearly stating what was the mismatch

  • Parameters

    • python_val: T
      • The actual value to be transformed.
    • python_type: Type[T]
      • The assumed type of the value (this matches the declared type on the function).
    • expected: LiteralType
      • Expected Literal Type.
  • Return Value: Literal

    • The Flyte Literal representation of the Python value.
def to_python_value(lv: Literal, expected_python_type: Type[T]) - > Optional[T]
  • Converts the given Literal to a Python Type. If the conversion cannot be done an AssertionError should be raised

  • Parameters

    • lv: Literal
      • The received literal Value.
    • expected_python_type: Type[T]
      • Expected native python type that should be returned.
  • Return Value: Optional[T]

    • The Python value representation of the Literal.
def from_binary_idl(binary_idl_object: Binary, expected_python_type: Type[T]) - > Optional[T]
  • This function primarily handles deserialization for untyped dicts, dataclasses, Pydantic BaseModels, and attribute access. For untyped dict, dataclass, and pydantic basemodel: Life Cycle (Untyped Dict as example): python val - > msgpack bytes - > binary literal scalar - > msgpack bytes - > python val (to_literal) (from_binary_idl) For attribute access: Life Cycle: python val - > msgpack bytes - > binary literal scalar - > resolved golang value - > binary literal scalar - > msgpack bytes - > python val (to_literal) (propeller attribute access) (from_binary_idl)

  • Parameters

    • binary_idl_object: Binary
      • The binary representation of the IDL object.
    • expected_python_type: Type[T]
      • The expected Python type after deserialization.
  • Return Value: Optional[T]

    • The deserialized Python value.
def to_html(python_val: T, expected_python_type: Type[T]) - > str
  • Converts any python val (dataframe, int, float) to a html string, and it will be wrapped in the HTML div

  • Parameters

    • python_val: T
      • The Python value to convert to HTML.
    • expected_python_type: Type[T]
      • The expected Python type of the value.
  • Return Value: str

    • An HTML string representation of the Python value.