You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Yifan Mai (Jira)" <ji...@apache.org> on 2019/10/10 23:43:00 UTC
[jira] [Created] (BEAM-8381) Typehints on DoFn subclass are
incorrect set on superclass
Yifan Mai created BEAM-8381:
-------------------------------
Summary: Typehints on DoFn subclass are incorrect set on superclass
Key: BEAM-8381
URL: https://issues.apache.org/jira/browse/BEAM-8381
Project: Beam
Issue Type: Bug
Components: sdk-py-core
Reporter: Yifan Mai
Suppose a parent DoFn with typehints is subclassed into a child DoFn with different typehints. The typehints will be incorrectly set on the parent DoFn class instead of the child DoFn class, causing type checking errors. This only happens if the parent already has typehints; if the parent has no typehints, then the typehints are correctly set on the child.
Here's a example test case. I would expect this example to run successfully, but instead it fails with {{apache_beam.typehints.decorators.TypeCheckError: Type hint violation for 'AddOneAndStringify': requires <class 'int'> but got <class 'str'> for element}}.
{code}
def test_do_fn_pipeline_pipeline_type_check_satisfied_with_subclassing(self):
@with_input_types(int)
@with_output_types(int)
class AddOne(beam.DoFn):
def add_one(elements):
return element + 1
def process(self, element):
return [add_one(element)]
@with_input_types(int)
@with_output_types(str)
class AddOneAndStringify(AddOne):
def process(self, element):
return [str(add_one(element))]
d = (self.p
| 'T' >> beam.Create([1, 2, 3]).with_output_types(int)
| 'AddOne' >> beam.ParDo(AddOne())
| 'AddOneAndStringify' >> beam.ParDo(AddOneAndStringify()))
assert_that(d, equal_to(['3', '4', '5']))
self.p.run()
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)