beam icon indicating copy to clipboard operation
beam copied to clipboard

[Bug]: Python type statement unsupported

Open pineapple-pokopo opened this issue 1 year ago • 0 comments

What happened?

Python 3.12 introduced the type statement to define type aliases.

Using the type statement with apache-beam 2.60.0 generates an error however:

TypeError: Type hints for a PTransform must be a non-sequence, a type, or a TypeConstraint. InputType is an instance of TypeAliasType.

Reproducible example:

import apache_beam as beam

type InputType = tuple[int, ...]


def print_element(element: InputType) -> InputType:
    print(element)

    return element


with beam.Pipeline() as pipeline:
    _ = pipeline | beam.Create([(1, 2)]).with_output_types(InputType) | beam.Map(print_element)

Using InputType: TypeAlias = tuple[int, ...] instead works fine.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components

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

pineapple-pokopo avatar Oct 18 '24 12:10 pineapple-pokopo