damccorm commented on code in PR #36703:
URL: https://github.com/apache/beam/pull/36703#discussion_r2482563442


##########
sdks/python/apache_beam/transforms/core.py:
##########
@@ -1507,25 +1507,29 @@ def _check_fn_use_yield_and_return(fn):
     source_code = _get_function_body_without_inners(fn)
     has_yield = False
     has_return = False
-    return_none_warning = (
-        "No iterator is returned by the process method in %s.",
-        fn.__self__.__class__)
+    has_return_none = False
     for line in source_code.split("\n"):
       lstripped_line = line.lstrip()
       if lstripped_line.startswith("yield ") or lstripped_line.startswith(
           "yield("):
         has_yield = True
-      if lstripped_line.startswith("return ") or lstripped_line.startswith(
-          "return("):
+      elif lstripped_line.rstrip() == "return":
         has_return = True
-        if lstripped_line.startswith(
-            "return None") or lstripped_line.rstrip() == "return":
-          _LOGGER.warning(return_none_warning)
-      if has_yield and has_return:
+      elif lstripped_line.startswith("return ") or lstripped_line.startswith(
+          "return("):
+        if lstripped_line.startswith("return None"):
+          has_return_none = True
+        else:

Review Comment:
   I think we can get rid of this `else` and always set `has_return` to True 
here (related to comment about condition below)



##########
sdks/python/apache_beam/transforms/core.py:
##########
@@ -1507,25 +1507,29 @@ def _check_fn_use_yield_and_return(fn):
     source_code = _get_function_body_without_inners(fn)
     has_yield = False
     has_return = False
-    return_none_warning = (
-        "No iterator is returned by the process method in %s.",
-        fn.__self__.__class__)
+    has_return_none = False
     for line in source_code.split("\n"):
       lstripped_line = line.lstrip()
       if lstripped_line.startswith("yield ") or lstripped_line.startswith(
           "yield("):
         has_yield = True
-      if lstripped_line.startswith("return ") or lstripped_line.startswith(
-          "return("):
+      elif lstripped_line.rstrip() == "return":
         has_return = True
-        if lstripped_line.startswith(
-            "return None") or lstripped_line.rstrip() == "return":
-          _LOGGER.warning(return_none_warning)
-      if has_yield and has_return:
+      elif lstripped_line.startswith("return ") or lstripped_line.startswith(
+          "return("):
+        if lstripped_line.startswith("return None"):
+          has_return_none = True
+        else:
+          has_return = True
+      if has_yield and (has_return or has_return_none):
         return True
 
-    if not has_yield and not has_return:
-      _LOGGER.warning(return_none_warning)
+    if not has_yield and not has_return and has_return_none:

Review Comment:
   Can this condition now just be:
   
   `if has_return_none`
   
   We already know that if `has_return_none` is true, then `has_yield` is false 
(otherwise we would've early returned). I think even if there is a mix of 
`return` and `return None`, we probably still want the warning.



##########
sdks/python/apache_beam/transforms/core.py:
##########
@@ -1507,25 +1507,29 @@ def _check_fn_use_yield_and_return(fn):
     source_code = _get_function_body_without_inners(fn)
     has_yield = False
     has_return = False
-    return_none_warning = (
-        "No iterator is returned by the process method in %s.",
-        fn.__self__.__class__)
+    has_return_none = False
     for line in source_code.split("\n"):
       lstripped_line = line.lstrip()
       if lstripped_line.startswith("yield ") or lstripped_line.startswith(
           "yield("):
         has_yield = True
-      if lstripped_line.startswith("return ") or lstripped_line.startswith(
-          "return("):
+      elif lstripped_line.rstrip() == "return":
         has_return = True
-        if lstripped_line.startswith(
-            "return None") or lstripped_line.rstrip() == "return":
-          _LOGGER.warning(return_none_warning)
-      if has_yield and has_return:
+      elif lstripped_line.startswith("return ") or lstripped_line.startswith(
+          "return("):
+        if lstripped_line.startswith("return None"):

Review Comment:
   ```suggestion
           if lstripped_line == "return None":
   ```
   
   I actually think we want to do this, because `return None, 'foo'` is 
actually a valid way to return a Tuple



##########
sdks/python/apache_beam/transforms/core.py:
##########
@@ -1507,25 +1507,29 @@ def _check_fn_use_yield_and_return(fn):
     source_code = _get_function_body_without_inners(fn)
     has_yield = False
     has_return = False
-    return_none_warning = (
-        "No iterator is returned by the process method in %s.",
-        fn.__self__.__class__)
+    has_return_none = False
     for line in source_code.split("\n"):
       lstripped_line = line.lstrip()
       if lstripped_line.startswith("yield ") or lstripped_line.startswith(
           "yield("):
         has_yield = True
-      if lstripped_line.startswith("return ") or lstripped_line.startswith(
-          "return("):
+      elif lstripped_line.rstrip() == "return":
         has_return = True
-        if lstripped_line.startswith(
-            "return None") or lstripped_line.rstrip() == "return":
-          _LOGGER.warning(return_none_warning)
-      if has_yield and has_return:
+      elif lstripped_line.startswith("return ") or lstripped_line.startswith(
+          "return("):
+        if lstripped_line.startswith("return None"):
+          has_return_none = True
+        else:
+          has_return = True
+      if has_yield and (has_return or has_return_none):
         return True
 
-    if not has_yield and not has_return:
-      _LOGGER.warning(return_none_warning)
+    if not has_yield and not has_return and has_return_none:
+      _LOGGER.warning(
+          "Process method returned None (element won't be emitted): %s."
+          " Check if intended.",
+          fn.__self__.__class__)
+    print(has_yield, has_return, has_return_none)

Review Comment:
   Do we need to print this tuple?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to