Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-8464

Python typehints: merge unions of tuples of the same size

Details

    • Bug
    • Status: Open
    • P3
    • Resolution: Unresolved
    • None
    • None
    • sdk-py-core

    Description

      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:

      def fn(element: Tuple[str, Any]):
        ....
      p | Create([('a', None), ('b', None)] + [('c', 1), ('d', 3)]) | ParDo(fn)
      

      This pipeline will fail with something like:

      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
      

      In test form:

        def test_union_of_tuple(self):
          self.assertCompatible(
              typehints.Tuple[str, typehints.Any],
              typehints.Union[typehints.Tuple[str, type(None)],
                              typehints.Tuple[str, int]])
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            udim Udi Meiri
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: