[ https://issues.apache.org/jira/browse/BEAM-8487?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Beam JIRA Bot reassigned BEAM-8487: ----------------------------------- Assignee: (was: Udi Meiri) > Python typehints: support forward references > -------------------------------------------- > > Key: BEAM-8487 > URL: https://issues.apache.org/jira/browse/BEAM-8487 > Project: Beam > Issue Type: Bug > Components: sdk-py-core > Reporter: Udi Meiri > Priority: P2 > Labels: stale-assigned > Time Spent: 2h 10m > Remaining Estimate: 0h > > 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: > {code} > 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)) > {code} > This results in: > {code} > > return issubclass(sub, base) > E TypeError: issubclass() arg 2 must be a class or tuple of classes > typehints.py:1168: TypeError > {code} > Example 2: > {code} > 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)) > {code} > This results in: > {code} > > raise ValueError('%s is not iterable' % type_hint) > E ValueError: typehints.List[str] is not iterable > typehints.py:1194: ValueError > {code} > where the non-iterable entity the error refers to is a string literal > ("typehints.List[str]"). -- This message was sent by Atlassian Jira (v8.3.4#803005)