File tree Expand file tree Collapse file tree 2 files changed +14
-23
lines changed
sdks/python/apache_beam/transforms Expand file tree Collapse file tree 2 files changed +14
-23
lines changed Original file line number Diff line number Diff line change @@ -1507,25 +1507,28 @@ def _check_fn_use_yield_and_return(fn):
15071507 source_code = _get_function_body_without_inners (fn )
15081508 has_yield = False
15091509 has_return = False
1510- return_none_warning = (
1511- "No iterator is returned by the process method in %s." ,
1512- fn .__self__ .__class__ )
1510+ has_return_none = False
15131511 for line in source_code .split ("\n " ):
15141512 lstripped_line = line .lstrip ()
15151513 if lstripped_line .startswith ("yield " ) or lstripped_line .startswith (
15161514 "yield(" ):
15171515 has_yield = True
1518- if lstripped_line .startswith ("return " ) or lstripped_line .startswith (
1516+ elif lstripped_line .rstrip () == "return" :
1517+ has_return_none = True
1518+ elif lstripped_line .startswith ("return " ) or lstripped_line .startswith (
15191519 "return(" ):
1520- has_return = True
1521- if lstripped_line . startswith (
1522- "return None" ) or lstripped_line . rstrip () == "return" :
1523- _LOGGER . warning ( return_none_warning )
1520+ if lstripped_line . startswith ( "return None" ):
1521+ has_return_none = True
1522+ else :
1523+ has_return = True
15241524 if has_yield and has_return :
15251525 return True
15261526
1527- if not has_yield and not has_return :
1528- _LOGGER .warning (return_none_warning )
1527+ if not has_yield and not has_return and has_return_none :
1528+ _LOGGER .warning (
1529+ "Process method returned None (element won't be emitted): %s. Check if intended." ,
1530+ fn .__self__ .__class__ )
1531+ print (has_yield , has_return , has_return_none )
15291532
15301533 return False
15311534 except Exception as e :
Original file line number Diff line number Diff line change 4040from apache_beam .typehints import row_type
4141from apache_beam .typehints import typehints
4242
43- RETURN_NONE_PARTIAL_WARNING = "No iterator is returned"
43+ RETURN_NONE_PARTIAL_WARNING = "Process method returned None "
4444
4545
4646class TestDoFn1 (beam .DoFn ):
@@ -114,12 +114,6 @@ def process(self, element):
114114 return None
115115
116116
117- class TestDoFn11 (beam .DoFn ):
118- """test process returning None (no return and no yield)"""
119- def process (self , element ):
120- pass
121-
122-
123117class TestDoFn12 (beam .DoFn ):
124118 """test process returning None (return statement without a value)"""
125119 def process (self , element ):
@@ -191,12 +185,6 @@ def test_dofn_with_explicit_return_none(self):
191185 assert RETURN_NONE_PARTIAL_WARNING in self ._caplog .text
192186 assert str (TestDoFn10 ) in self ._caplog .text
193187
194- def test_dofn_with_implicit_return_none_missing_return_and_yield (self ):
195- with self ._caplog .at_level (logging .WARNING ):
196- beam .ParDo (TestDoFn11 ())
197- assert RETURN_NONE_PARTIAL_WARNING in self ._caplog .text
198- assert str (TestDoFn11 ) in self ._caplog .text
199-
200188 def test_dofn_with_implicit_return_none_return_without_value (self ):
201189 with self ._caplog .at_level (logging .WARNING ):
202190 beam .ParDo (TestDoFn12 ())
You can’t perform that action at this time.
0 commit comments