flytekit icon indicating copy to clipboard operation
flytekit copied to clipboard

Add to_string method to literal

Open pingsutw opened this issue 1 year ago • 0 comments

Tracking issue

NA

Why are the changes needed?

It's hard to read Literal.__str__, especially when you have a nested list or dict.

What changes were proposed in this pull request?

Add to_string to Literal to customize the representational string

How was this patch tested?

int_literal = Literal(scalar=Scalar(primitive=Primitive(integer=1)))
print(int_literal)
large_dict = Literal(map=LiteralMap({str(i): Literal(scalar=Scalar(primitive=Primitive(integer=i))) for i in range(100)}))
print(large_dict)
union_literal = Literal(scalar=Scalar(union=Union(value=large_dict, stored_type=LiteralType(SimpleType.INTEGER))))
print(union_literal)

Before: Screenshot 2024-11-05 at 3 39 10 PM

After: Screenshot 2024-11-05 at 3 38 35 PM

pingsutw avatar Nov 05 '24 23:11 pingsutw