You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Udi Meiri (Jira)" <ji...@apache.org> on 2019/10/25 18:17:00 UTC
[jira] [Created] (BEAM-8487) Python typehints: support forward
references
Udi Meiri created BEAM-8487:
-------------------------------
Summary: 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
Assignee: Udi Meiri
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)