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

Python typehints: support type hint decorators with ptransform_fn

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: Not applicable
    • Component/s: sdk-py-core
    • Labels:
      None

      Description

      In this example, the input type hint does not currently get propagated (TypeCheckError is not raise):

        def test_typed_ptransform_fn(self):
          # Test that type hints are propagated to the created PTransform.
          @beam.ptransform_fn
          @typehints.with_input_types(int)
          def MyMap(pcoll):
            return pcoll | beam.ParDo(lambda x: [x])
      
          self.assertListEqual([1, 2, 3], [1, 2, 3] | MyMap())
          with self.assertRaises(typehints.TypeCheckError):
            _ = ['a'] | MyMap()
      

      The fix is relatively simple but might break existing pipelines that have old (unchecked) hints.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                udim Udi Meiri
                Reporter:
                udim Udi Meiri
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m