liferoad commented on code in PR #25743:
URL: https://github.com/apache/beam/pull/25743#discussion_r1130377411
##########
sdks/python/apache_beam/transforms/core.py:
##########
@@ -1387,6 +1388,47 @@ def partition_for(self, element, num_partitions, *args,
**kwargs):
return self._fn(element, num_partitions, *args, **kwargs)
+def _get_function_body_without_inners(func):
+ source_lines = inspect.getsourcelines(func)[0]
Review Comment:
I tried this as my first idea. It does not work:
```
def bar():
yield "bar"
list(dis.get_instructions(bar))
```
This generates:
```
[Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval='bar',
argrepr="'bar'", offset=0, starts_line=2, is_jump_target=False),
Instruction(opname='YIELD_VALUE', opcode=86, arg=None, argval=None,
argrepr='', offset=2, starts_line=None, is_jump_target=False),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='',
offset=4, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None,
argrepr='None', offset=6, starts_line=None, is_jump_target=False),
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None,
argrepr='', offset=8, starts_line=None, is_jump_target=False)]
```
`RETURN_VALUE` is always there no matter the function contains yield or
return. So I decided to use this simple way by just checking the source code.
--
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]