You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Kenneth Knowles (Jira)" <ji...@apache.org> on 2019/11/02 20:50:00 UTC

[jira] [Commented] (BEAM-8464) Python typehints: merge unions of tuples of the same size

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

Kenneth Knowles commented on BEAM-8464:
---------------------------------------

The typing rule for "Union[X, Y] <: Z" (the symbol <: is standard for subtyping) should check that "X <: Z" and "Y <: Z" (modulo the idiosyncrasies of "compatibility" in gradual typing versus subtyping... it looks like you are concerned about subtyping here)

Are you writing these rules yourself or using an off-the-shelf library?

> 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)