apache / apache/beam

Support type hint annotations on CombineFn add_input() and extract_output()

Open
#20,513 0 comments 0 reactions 0 assignees View on GitHub
core improvement P3 python types
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

Similar to the tweaks for supporting native type hints on the `PTransform.expand()` method (https://issues.apache.org/jira/browse/BEAM-10258), it would be beneficial if the `CombineFn` class also received similar treatment, offering a way to provide type hints through the native Python hinting interface.

Adding hints to the CombineFn's `add_input()` and `extract_output()` methods should be sufficient for providing the equivalent behavior of annotating the class with beam typehint decorators, e.g.,
```

@beam.typehints.with_input_types(int)
@beam.typehints.with_output_types(bool)
class MyCombineFn(CombineFn):

...

```

vs
```

class MyCombineFn(CombineFn):
def add_input(self, accumulator: float, element: int):
...

def extract_output(self, accumulator: float) -> bool
...

```

Imported from Jira [BEAM-10418](https://issues.apache.org/jira/browse/BEAM-10418). Original Jira may contain additional context.
Reported by: metzen.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing native type-hint support for PTransform.expand(), then trace how CombineFn.add_input() and extract_output() are inspected for type information. Identify the corresponding implementation and test locations, and verify that method annotations provide the same behavior as the stated typehint decorators.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-engineering
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.