JonathanHourany commented on a change in pull request #15539:
URL: https://github.com/apache/beam/pull/15539#discussion_r712501402



##########
File path: sdks/python/apache_beam/typehints/native_type_compatibility.py
##########
@@ -107,7 +107,7 @@ def _match_is_exactly_iterable(user_type):
 def match_is_named_tuple(user_type):
   return (
       _safe_issubclass(user_type, typing.Tuple) and
-      hasattr(user_type, '_field_types'))
+      hasattr(user_type, '__annotations__'))

Review comment:
       Good catch. The only other object I know of off the top of my head that 
has `__annotations__` are `dataclasses`, but dataclasses aren't a subclass of 
`typing.Tuple` so this function should still return `false` for those 
instances. AFIAK it'll only return true if the dataclass sublcasses 
`typing.Tuple` or `typing.NamedTuple`
   ```python
   >>> from dataclasses import dataclass
   >>> from apache_beam.typehints.native_type_compatibility import 
match_is_named_tuple
   >>> @dataclass
     ...:  class TestDS():
     ...:      foo: int
   >>> match_is_named_tuple(TestDS)
   False
   ```
   However
   ```python
   >>> from apache_beam.typehints.native_type_compatibility import 
match_is_named_tuple
   >>> @dataclass
      ...: class TestDS(typing.NamedTuple):
      ...:     foo: int
   >>> match_is_named_tuple(TestDS)
    True
   ```
   
   edit: updated example




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to