beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rober...@apache.org
Subject [1/2] beam git commit: None should be a valid return element
Date Wed, 21 Jun 2017 03:34:16 GMT
Repository: beam
Updated Branches:
  refs/heads/master 7b4f5eeaa -> a40d11c8e


None should be a valid return element


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/5a95d620
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/5a95d620
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/5a95d620

Branch: refs/heads/master
Commit: 5a95d620ad0c7f427a5b849059a0215c3f061a58
Parents: 7b4f5ee
Author: Sourabh Bajaj <sourabhbajaj@google.com>
Authored: Tue Jun 20 18:53:50 2017 -0700
Committer: Robert Bradshaw <robertwb@gmail.com>
Committed: Tue Jun 20 20:34:04 2017 -0700

----------------------------------------------------------------------
 sdks/python/apache_beam/typehints/trivial_inference.py      | 3 +--
 sdks/python/apache_beam/typehints/trivial_inference_test.py | 7 +++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/5a95d620/sdks/python/apache_beam/typehints/trivial_inference.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/typehints/trivial_inference.py b/sdks/python/apache_beam/typehints/trivial_inference.py
index 977ea06..c740596 100644
--- a/sdks/python/apache_beam/typehints/trivial_inference.py
+++ b/sdks/python/apache_beam/typehints/trivial_inference.py
@@ -40,8 +40,7 @@ def instance_to_type(o):
   """
   t = type(o)
   if o is None:
-    # TODO(robertwb): Eliminate inconsistent use of None vs. NoneType.
-    return None
+    return type(None)
   elif t not in typehints.DISALLOWED_PRIMITIVE_TYPES:
     if t == types.InstanceType:
       return o.__class__

http://git-wip-us.apache.org/repos/asf/beam/blob/5a95d620/sdks/python/apache_beam/typehints/trivial_inference_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/typehints/trivial_inference_test.py b/sdks/python/apache_beam/typehints/trivial_inference_test.py
index ac00baa..e7f451d 100644
--- a/sdks/python/apache_beam/typehints/trivial_inference_test.py
+++ b/sdks/python/apache_beam/typehints/trivial_inference_test.py
@@ -60,6 +60,13 @@ class TrivialInferenceTest(unittest.TestCase):
     self.assertReturnType(any_tuple,
                           reverse, [trivial_inference.Const((1, 2, 3))])
 
+  def testNoneReturn(self):
+    def func(a):
+      if a == 5:
+        return a
+      return None
+    self.assertReturnType(typehints.Union[int, type(None)], func, [int])
+
   def testListComprehension(self):
     self.assertReturnType(
         typehints.List[int],


Mime
View raw message