File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
sdks/python/apache_beam/transforms Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -1514,19 +1514,20 @@ def _check_fn_use_yield_and_return(fn):
15141514 "yield(" ):
15151515 has_yield = True
15161516 elif lstripped_line .rstrip () == "return" :
1517- has_return_none = True
1517+ has_return = True
15181518 elif lstripped_line .startswith ("return " ) or lstripped_line .startswith (
15191519 "return(" ):
15201520 if lstripped_line .startswith ("return None" ):
15211521 has_return_none = True
15221522 else :
15231523 has_return = True
1524- if has_yield and has_return :
1524+ if has_yield and ( has_return or has_return_none ) :
15251525 return True
15261526
15271527 if not has_yield and not has_return and has_return_none :
15281528 _LOGGER .warning (
1529- "Process method returned None (element won't be emitted): %s. Check if intended." ,
1529+ "Process method returned None (element won't be emitted): %s."
1530+ " Check if intended." ,
15301531 fn .__self__ .__class__ )
15311532 print (has_yield , has_return , has_return_none )
15321533
Original file line number Diff line number Diff line change @@ -114,10 +114,12 @@ def process(self, element):
114114 return None
115115
116116
117- class TestDoFn12 (beam .DoFn ):
118- """test process returning None (return statement without a value) """
117+ class TestDoFn11 (beam .DoFn ):
118+ """test process returning None in a filter pattern """
119119 def process (self , element ):
120- return
120+ if element == 0 :
121+ return
122+ return element
121123
122124
123125class TestDoFnStateful (beam .DoFn ):
@@ -185,11 +187,10 @@ def test_dofn_with_explicit_return_none(self):
185187 assert RETURN_NONE_PARTIAL_WARNING in self ._caplog .text
186188 assert str (TestDoFn10 ) in self ._caplog .text
187189
188- def test_dofn_with_implicit_return_none_return_without_value (self ):
190+ def test_dofn_with_implicit_return_none_and_value (self ):
189191 with self ._caplog .at_level (logging .WARNING ):
190- beam .ParDo (TestDoFn12 ())
191- assert RETURN_NONE_PARTIAL_WARNING in self ._caplog .text
192- assert str (TestDoFn12 ) in self ._caplog .text
192+ beam .ParDo (TestDoFn11 ())
193+ assert RETURN_NONE_PARTIAL_WARNING not in self ._caplog .text
193194
194195
195196class PartitionTest (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments