beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rober...@apache.org
Subject [beam] branch master updated: [BEAM-6588] Fix type hints for beam.Filter
Date Wed, 03 Apr 2019 07:39:58 GMT
This is an automated email from the ASF dual-hosted git repository.

robertwb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 87c679d  [BEAM-6588] Fix type hints for beam.Filter
     new 580e919  Merge pull request #8185 [BEAM-6588] Fix type hints for beam.Filter
87c679d is described below

commit 87c679d65451a5172cfbdd6b9aa329b2cfcccafb
Author: Robert Bradshaw <robertwb@google.com>
AuthorDate: Mon Apr 1 16:43:49 2019 +0200

    [BEAM-6588] Fix type hints for beam.Filter
---
 sdks/python/apache_beam/transforms/core.py               | 2 +-
 sdks/python/apache_beam/typehints/typed_pipeline_test.py | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/sdks/python/apache_beam/transforms/core.py b/sdks/python/apache_beam/transforms/core.py
index 1d095e8..ab1832d 100644
--- a/sdks/python/apache_beam/transforms/core.py
+++ b/sdks/python/apache_beam/transforms/core.py
@@ -1246,7 +1246,7 @@ def Filter(fn, *args, **kwargs):  # pylint: disable=invalid-name
   if (output_hint is None
       and get_type_hints(wrapper).input_types
       and get_type_hints(wrapper).input_types[0]):
-    output_hint = get_type_hints(wrapper).input_types[0]
+    output_hint = get_type_hints(wrapper).input_types[0][0]
   if output_hint:
     get_type_hints(wrapper).set_output_types(typehints.Iterable[output_hint])
   # pylint: disable=protected-access
diff --git a/sdks/python/apache_beam/typehints/typed_pipeline_test.py b/sdks/python/apache_beam/typehints/typed_pipeline_test.py
index b630307..2e461f9 100644
--- a/sdks/python/apache_beam/typehints/typed_pipeline_test.py
+++ b/sdks/python/apache_beam/typehints/typed_pipeline_test.py
@@ -101,6 +101,13 @@ class MainInputTest(unittest.TestCase):
     with self.assertRaises(typehints.TypeCheckError):
       [1, 2, 3] | (beam.ParDo(my_do_fn) | 'again' >> beam.ParDo(my_do_fn))
 
+  def test_filter_type_hint(self):
+    @typehints.with_input_types(int)
+    def filter_fn(data):
+      return data % 2
+
+    self.assertEquals([1, 3], [1, 2, 3] | beam.Filter(filter_fn))
+
 
 class NativeTypesTest(unittest.TestCase):
 


Mime
View raw message