From dac4061ca3f9f0f5093c42bb8d018ba20d84b0ea Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Mon, 6 Nov 2023 14:49:53 -0500 Subject: [PATCH] Change comment, refine general check --- sdks/python/apache_beam/typehints/typehints.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdks/python/apache_beam/typehints/typehints.py b/sdks/python/apache_beam/typehints/typehints.py index c7da528c0b4f..d18767d2847b 100644 --- a/sdks/python/apache_beam/typehints/typehints.py +++ b/sdks/python/apache_beam/typehints/typehints.py @@ -1051,14 +1051,16 @@ def _consistent_with_check_(self, sub): # The empty tuple is consistent with Iterator[T] for any T. return True # Each element in the hetrogenious tuple must be consistent with - # the iterator type. - # E.g. Tuple[A, B] < Iterable[C] if A < C and B < C. + # the collection type. + # E.g. Tuple[A, B] < Collection[C] if A < C and B < C. return all( is_consistent_with(elem, self.inner_type) for elem in sub.tuple_types) elif not isinstance(sub, TypeConstraint): - if getattr(sub, '__origin__', None) is not None: - return issubclass(sub, abc.Collection) + if getattr(sub, '__origin__', None) is not None and getattr( + sub, '__args__', None) is not None: + return issubclass(sub, abc.Collection) and is_consistent_with( + sub.__args__, self.inner_type) return False def __getitem__(self, type_param):