Skip to content

Commit

Permalink
fix(sdk): Components - Fixed handling of typing.NamedTuple in Python …
Browse files Browse the repository at this point in the history
…3.9 (#4614)

Python 3.9 has dropped support for `typing.NamedTuple(...)`.`_field_types` in favor of `__annotations__` which in turn does not exist in Python 3.5.
  • Loading branch information
Ark-kun committed Oct 17, 2020
1 parent 02b0899 commit 8699a05
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sdk/python/kfp/components/_python_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,14 @@ def annotation_to_type_struct(annotation):
#Analyzing the return type annotations.
return_ann = signature.return_annotation
if hasattr(return_ann, '_fields'): #NamedTuple
# Getting field type annotations.
# __annotations__ does not exist in python 3.5 and earlier
# _field_types does not exist in python 3.9 and later
field_annotations = getattr(return_ann, '__annotations__', None) or getattr(return_ann, '_field_types', None)
for field_name in return_ann._fields:
type_struct = None
if hasattr(return_ann, '_field_types'):
type_struct = annotation_to_type_struct(return_ann._field_types.get(field_name, None))
if field_annotations:
type_struct = annotation_to_type_struct(field_annotations.get(field_name, None))

output_name = _make_name_unique_by_adding_index(field_name, output_names, '_')
output_names.add(output_name)
Expand Down

0 comments on commit 8699a05

Please sign in to comment.