damccorm opened a new issue, #19954: URL: https://github.com/apache/beam/issues/19954
Typehints may be given as string literals: https://www.python.org/dev/peps/pep-0484/#forward-references These are currently not evaluated and result in errors. Example 1: ``` def test_typed_callable_string_hints(self): def do_fn(element: 'int') -> 'typehints.List[str]': return [[str(element)] * 2] result = [1, 2] | beam.ParDo(do_fn) self.assertEqual([['1', '1'], ['2', '2']], sorted(result)) ``` This results in: ``` > return issubclass(sub, base) E TypeError: issubclass() arg 2 must be a class or tuple of classes typehints.py:1168: TypeError ``` Example 2: ``` def test_typed_dofn_string_hints(self): class MyDoFn(beam.DoFn): def process(self, element: 'int') -> 'typehints.List[str]': return [[str(element)] * 2] result = [1, 2] | beam.ParDo(MyDoFn()) self.assertEqual([['1', '1'], ['2', '2']], sorted(result)) ``` This results in: ``` > raise ValueError('%s is not iterable' % type_hint) E ValueError: typehints.List[str] is not iterable typehints.py:1194: ValueError ``` where the non-iterable entity the error refers to is a string literal ("typehints.List[str]"). Imported from Jira [BEAM-8487](https://issues.apache.org/jira/browse/BEAM-8487). Original Jira may contain additional context. Reported by: udim. -- 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]
