apache / apache/beam

[Feature Request]: Support TypedDict hint in Apache Beam.

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

Description

### What would you like to happen?

CoGroupByKey produces Dict[K, Union[...]], which is narrower than TypedDict. If the user follows the CoGroupByKey with a ParDo where the function takes TypeDict as input, e.g. `ParDo(fn(element: TypedDict))`, then the type check in Beam fails.

Users having types like:

```
myTypeDict = TypedDict(
'myTypeDict', {
'field_1': List[Field1Type],
'field_2': List[Field2Type],
})
```

are using less specific hints like `myLessSpecificDict = Dict(str, Union[List[Field1Type], List[Field2Type]])` in order to satisfy beams typing.

We could have a first-class typehint TypeDict, which may be easier once we deprecate Python 3.7.

### Issue Priority

Priority: 3 (nice-to-have improvement)

### Issue Components

- [X] Component: Python SDK
- [ ] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Samza Runner
- [ ] Component: Twister2 Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.