Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to_string method to literal #2906

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

pingsutw
Copy link
Member

@pingsutw pingsutw commented Nov 5, 2024

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

Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Kevin Su <pingsutw@apache.org>
@@ -1605,7 +1605,7 @@ async def async_to_python_value( # type: ignore
except AttributeError:
raise TypeTransformerFailedError(
(
f"The expected python type is '{expected_python_type}' but the received Flyte literal value "
f"The expected python type is '{expected_python_type}' but the received {lv} "
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-11-05 at 3 31 10 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Kevin Su <pingsutw@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant