Skip to content

Commit

Permalink
Adds type information to flytekit.models in repr (#2389)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
  • Loading branch information
thomasjpfan committed May 6, 2024
1 parent 8d258c4 commit 0869786
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion flytekit/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def short_string(self):
:rtype: Text
"""
literal_str = re.sub(r"\s+", " ", str(self.to_flyte_idl())).strip()
return f"<FlyteLiteral {literal_str}>"
type_str = type(self).__name__
return f"<FlyteLiteral({type_str}) {literal_str}>"

def verbose_string(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/flytekit/unit/core/test_promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def wf(i: int, j: int):

# without providing the _inputs_not_allowed or _ignorable_inputs, all inputs to lp become required,
# which is incorrect
with pytest.raises(FlyteAssertion, match="Missing input `i` type `<FlyteLiteral simple: INTEGER>`"):
with pytest.raises(FlyteAssertion, match=r"Missing input `i` type `<FlyteLiteral\(LiteralType\) simple: INTEGER>`"):
create_and_link_node_from_remote(ctx, lp)

# Even if j is not provided it will default
Expand Down
2 changes: 1 addition & 1 deletion tests/flytekit/unit/core/test_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ def wf2(a: typing.Union[int, str]) -> typing.Union[int, str]:
match=re.escape(
"Error encountered while executing 'wf2':\n"
f" Failed to convert inputs of task '{prefix}tests.flytekit.unit.core.test_type_hints.t2':\n"
' Cannot convert from <FlyteLiteral scalar { union { value { scalar { primitive { string_value: "2" } } } '
' Cannot convert from <FlyteLiteral(Literal) scalar { union { value { scalar { primitive { string_value: "2" } } } '
'type { simple: STRING structure { tag: "str" } } } }> to typing.Union[float, dict] (using tag str)'
),
):
Expand Down
7 changes: 7 additions & 0 deletions tests/flytekit/unit/models/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,10 @@ def test_auth_role_empty():
x = obj.to_flyte_idl()
y = _common.AuthRole.from_flyte_idl(x)
assert y == obj


def test_short_string_raw_output_data_config():
""""""
obj = _common.RawOutputDataConfig("s3://bucket")
assert "FlyteLiteral(RawOutputDataConfig)" in obj.short_string()
assert "FlyteLiteral(RawOutputDataConfig)" in repr(obj)

0 comments on commit 0869786

Please sign in to comment.