[ 
https://issues.apache.org/jira/browse/BEAM-8464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16978590#comment-16978590
 ] 

Udi Meiri commented on BEAM-8464:
---------------------------------

We appear to have the check you're referring to 
(https://github.com/apache/beam/blob/db11e06184cad5913cf45e694748f4665bf2f097/sdks/python/apache_beam/typehints/typehints.py#L1164-L1165)
but it didn't work in this case for some reason.

We are currently maintaining our own rules in typehints.py, until an 
off-the-shelf library is available (I'm not aware of any, and pytypes doesn't 
support Py3.7 yet).


> Python typehints: merge unions of tuples of the same size
> ---------------------------------------------------------
>
>                 Key: BEAM-8464
>                 URL: https://issues.apache.org/jira/browse/BEAM-8464
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-py-core
>            Reporter: Udi Meiri
>            Priority: Minor
>
> When inferring PCollection element types, merge Unions of identically-sized 
> Tuples:
> Union[Tuple[a, b], Tuple[c, d]] => Tuple[Union[a, c], Union[b, d]]
> cc: [~robertwb]
> Example:
> {code}
> def fn(element: Tuple[str, Any]):
>   ....
> p | Create([('a', None), ('b', None)] + [('c', 1), ('d', 3)]) | ParDo(fn)
> {code}
> This pipeline will fail with something like:
> {code}
> apache_beam.typehints.decorators.TypeCheckError: Type hint violation for 
> 'ParDo': requires Tuple[str, Any] but got Union[Tuple[str, NoneType], 
> Tuple[str, int]] for element
> {code}
> In test form:
> {code}
>   def test_union_of_tuple(self):
>     self.assertCompatible(
>         typehints.Tuple[str, typehints.Any],
>         typehints.Union[typehints.Tuple[str, type(None)],
>                         typehints.Tuple[str, int]])
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to