Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdks/python/apache_beam/transforms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,8 @@ def _check_fn_use_yield_and_return(fn):
"yield("):
has_yield = True
elif lstripped_line.rstrip() == "return":
has_return = True
# Return is likely used to exit the function - ok to use with 'yield'.
pass
elif lstripped_line.startswith("return ") or lstripped_line.startswith(
"return("):
if lstripped_line.rstrip() == "return None" or lstripped_line.rstrip(
Expand Down
9 changes: 9 additions & 0 deletions sdks/python/apache_beam/transforms/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
RETURN_NONE_PARTIAL_WARNING = "Process method returned None"


class TestDoFn0(beam.DoFn):
"""Returning without a value is allowed"""
def process(self, element):
if not element:
return
yield element


class TestDoFn1(beam.DoFn):
def process(self, element):
yield element
Expand Down Expand Up @@ -174,6 +182,7 @@ def test_dofn_with_yield_and_return(self):

with self._caplog.at_level(logging.WARNING):
assert beam.ParDo(sum)
assert beam.ParDo(TestDoFn0())
assert beam.ParDo(TestDoFn1())
assert beam.ParDo(TestDoFn2())
assert beam.ParDo(TestDoFn4())
Expand Down
Loading