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

Fix list of annotated structured dataset #1817

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,15 @@ def get_transformer(cls, python_type: Type) -> TypeTransformer[T]:

python_type = args[0]

if python_type in cls._REGISTRY:
# this makes sure that if it's a list/dict of annotated types, we hit the unwrapping code in step 2
# see test_list_of_annotated in test_structured_dataset.py
if (
(not hasattr(python_type, "__origin__"))
or (
hasattr(python_type, "__origin__")
and (python_type.__origin__ is not list and python_type.__origin__ is not dict)
)
) and python_type in cls._REGISTRY:
return cls._REGISTRY[python_type]

# Step 2
Expand Down
14 changes: 14 additions & 0 deletions tests/flytekit/unit/core/test_structured_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,17 @@

with pytest.raises(NotImplementedError, match="Could not find a renderer for <class 'int'> in"):
StructuredDatasetTransformerEngine().to_html(FlyteContextManager.current_context(), 3, int)


def test_list_of_annotated():
WineDataset = Annotated[

Check warning on line 499 in tests/flytekit/unit/core/test_structured_dataset.py

View check run for this annotation

Codecov / codecov/patch

tests/flytekit/unit/core/test_structured_dataset.py#L498-L499

Added lines #L498 - L499 were not covered by tests
StructuredDataset,
kwtypes(
alcohol=float,
malic_acid=float,
),
]

@task
def no_op(data: WineDataset) -> typing.List[WineDataset]:
return [data]

Check warning on line 509 in tests/flytekit/unit/core/test_structured_dataset.py

View check run for this annotation

Codecov / codecov/patch

tests/flytekit/unit/core/test_structured_dataset.py#L507-L509

Added lines #L507 - L509 were not covered by tests
Loading