[
https://issues.apache.org/jira/browse/BEAM-5878?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16833906#comment-16833906
]
Juta Staes edited comment on BEAM-5878 at 5/6/19 3:22 PM:
----------------------------------------------------------
I added a test to check the current behavior:
[https://github.com/apache/beam/pull/8505]
Test:
{code:java}
pipeline = TestPipeline()
class MyDoFn(beam.DoFn):
def process(self, element, *s, bound=500):
return [min(sum(s) + element, bound)]
pcoll = pipeline | 'start' >> beam.Create([6, 3, 1])
result2 = pcoll | 'sum2' >> beam.ParDo(MyDoFn(), 5, 8){code}
Error:
{code:java}
======================================================================
ERROR: test_do_fn_keyword_only_args
(apache_beam.transforms.tranforms_keyword_only_args_test.KeywordOnlyArgsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/mnt/c/Users/Juta/Documents/02-projects/apache/beam/sdks/python/apache_beam/runners/common.py",
line 751, in process
return self.do_fn_invoker.invoke_process(windowed_value)
File
"/mnt/c/Users/Juta/Documents/02-projects/apache/beam/sdks/python/apache_beam/runners/common.py",
line 564, in invoke_process
windowed_value, additional_args, additional_kwargs, output_processor)
File
"/mnt/c/Users/Juta/Documents/02-projects/apache/beam/sdks/python/apache_beam/runners/common.py",
line 635, in _invoke_process_per_window
windowed_value, self.process_method(*args_for_process))
TypeError: process() missing 1 required keyword-only argument: 'bound'{code}
was (Author: juta):
I added a test to check the current behavior:
[https://github.com/apache/beam/pull/8505]
For this test:
{code:java}
pipeline = TestPipeline()
class MyDoFn(beam.DoFn):
def process(self, element, *s, bound=500):
return [min(sum(s) + element, bound)]
pcoll = pipeline | 'start' >> beam.Create([6, 3, 1])
result2 = pcoll | 'sum2' >> beam.ParDo(MyDoFn(), 5, 8){code}
Error:
{code:java}
======================================================================
ERROR: test_do_fn_keyword_only_args
(apache_beam.transforms.tranforms_keyword_only_args_test.KeywordOnlyArgsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/mnt/c/Users/Juta/Documents/02-projects/apache/beam/sdks/python/apache_beam/runners/common.py",
line 751, in process
return self.do_fn_invoker.invoke_process(windowed_value)
File
"/mnt/c/Users/Juta/Documents/02-projects/apache/beam/sdks/python/apache_beam/runners/common.py",
line 564, in invoke_process
windowed_value, additional_args, additional_kwargs, output_processor)
File
"/mnt/c/Users/Juta/Documents/02-projects/apache/beam/sdks/python/apache_beam/runners/common.py",
line 635, in _invoke_process_per_window
windowed_value, self.process_method(*args_for_process))
TypeError: process() missing 1 required keyword-only argument: 'bound'{code}
> Support DoFns with Keyword-only arguments in Python 3.
> ------------------------------------------------------
>
> Key: BEAM-5878
> URL: https://issues.apache.org/jira/browse/BEAM-5878
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Valentyn Tymofieiev
> Assignee: Juta Staes
> Priority: Minor
> Time Spent: 1h 50m
> Remaining Estimate: 0h
>
> Python 3.0 [adds a possibility|https://www.python.org/dev/peps/pep-3102/] to
> define functions with keyword-only arguments.
> Currently Beam does not handle them correctly. [~ruoyu] pointed out [one
> place|https://github.com/apache/beam/blob/a56ce43109c97c739fa08adca45528c41e3c925c/sdks/python/apache_beam/typehints/decorators.py#L118]
> in our codebase that we should fix: in Python in 3.0 inspect.getargspec()
> will fail on functions with keyword-only arguments, but a new method
> [inspect.getfullargspec()|https://docs.python.org/3/library/inspect.html#inspect.getfullargspec]
> supports them.
> There may be implications for our (best-effort) type-hints machinery.
> We should also add a Py3-only unit tests that covers DoFn's with keyword-only
> arguments once Beam Python 3 tests are in a good shape.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)