Details
-
Bug
-
Status: Open
-
P3
-
Resolution: Unresolved
-
None
-
None
-
None
Description
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]").