apache / apache/beam

Python typehints: merge unions of tuples of the same size

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

Description

When inferring PCollection element types, merge Unions of identically-sized Tuples:
Union[Tuple[a, b], Tuple[c, d]] =\> Tuple[Union[a, c], Union[b, d]]

cc: [~robertwb]

Example:
```

def fn(element: Tuple[str, Any]):
....
p | Create([('a', None), ('b', None)] + [('c', 1), ('d',
3)]) | ParDo(fn)

```

This pipeline will fail with something like:
```

apache_beam.typehints.decorators.TypeCheckError: Type hint violation for 'ParDo': requires Tuple[str,
Any] but got Union[Tuple[str, NoneType], Tuple[str, int]] for element

```

In test form:
```

def test_union_of_tuple(self):
self.assertCompatible(
typehints.Tuple[str, typehints.Any],

typehints.Union[typehints.Tuple[str, type(None)],
typehints.Tuple[str,
int]])

```

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

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.