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
>>> import typing
>>> @dataclass
...: class TestDS():
...: foo: int
>>> issubclass(TestDS, typing.Tuple)
False
```
However
```python
>>> @dataclass
...: class TestDS(typing.NamedTuple):
...: foo: int
>>> issubclass(TestDS, typing.Tuple)
True
```
--
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]