From e1eda5073ec78e6d44319a7ee41ff1cf698377c7 Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Thu, 19 Jan 2023 19:21:41 +0000 Subject: [PATCH] Add unit test to cover non built-in GenericAlias types --- .../apache_beam/typehints/typehints_test.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdks/python/apache_beam/typehints/typehints_test.py b/sdks/python/apache_beam/typehints/typehints_test.py index cd7f9fc4e30fc..d8893a3f474a2 100644 --- a/sdks/python/apache_beam/typehints/typehints_test.py +++ b/sdks/python/apache_beam/typehints/typehints_test.py @@ -104,6 +104,15 @@ class SubClass(SuperClass): pass +T = typing.TypeVar('T') + + +class NonBuiltInGeneric(typing.NamedTuple('Entry', [('Field1', T), + ('Field2', T)]), + typing.Generic[T]): + pass + + class TypeHintTestCase(unittest.TestCase): def assertCompatible(self, base, sub): # pylint: disable=invalid-name base, sub = native_type_compatibility.convert_to_beam_types([base, sub]) @@ -1645,5 +1654,12 @@ def test_pipe_operator_as_union(self): native_type_compatibility.convert_to_beam_type(type_b)) +class TestNonBuiltInGenerics(unittest.TestCase): + def test_no_error_thrown(self): + input = NonBuiltInGeneric[str] + output = typehints.normalize(input) + self.assertEqual(input, output) + + if __name__ == '__main__': unittest.main()