Skip to content
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
3 changes: 2 additions & 1 deletion sdks/python/apache_beam/coders/typecoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def get_coder(self, typehint):
raise RuntimeError(
'Coder registry has no fallback coder. This can happen if the '
'fast_coders module could not be imported.')
if isinstance(typehint, typehints.IterableTypeConstraint):
if isinstance(typehint, (typehints.IterableTypeConstraint,
typehints.ListConstraint)):
return coders.IterableCoder.from_type_hint(typehint, self)
elif typehint is None:
# In some old code, None is used for Any.
Expand Down
12 changes: 12 additions & 0 deletions sdks/python/apache_beam/coders/typecoders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ def test_iterable_coder(self):
self.assertEqual(expected_coder, real_coder)
self.assertEqual(real_coder.encode(values), expected_coder.encode(values))

def test_list_coder(self):
real_coder = typecoders.registry.get_coder(typehints.List[bytes])
expected_coder = coders.IterableCoder(coders.BytesCoder())
values = [b'abc', b'xyz']
self.assertEqual(expected_coder, real_coder)
self.assertEqual(real_coder.encode(values), expected_coder.encode(values))
# IterableCoder.decode() always returns a list. Its implementation,
# IterableCoderImpl, *can* return a non-list if it is provided a read_state
# object, but this is not possible using the atomic IterableCoder interface.
self.assertIs(list,
type(expected_coder.decode(expected_coder.encode(values))))


if __name__ == '__main__':
unittest.main()