How to type hint a PTransform that accepts a tuple of PCollections as input in python Apache Beam? - Stack Overflow

class MyTransform(beam.PTransform):def expand(self, pcolls: tuple[beam.PCollection[int], beam.PCollecti

class MyTransform(beam.PTransform):
  def expand(self, pcolls: tuple[beam.PCollection[int], beam.PCollection[str]]) -> beam.PCollection[str]:
    pcoll1, pcoll2 = pcolls
    strified = pcoll1 | beam.Map(lambda x: str(x))

    return (pcoll1, pcoll2) | beam.Flatten()

with beam.Pipeline() as p:
  pcoll1 = p | beam.Create([1, 2, 3])
  pcoll2 = p | beam.Create(["a", "b", "c"])

  result = (pcoll1, pcoll2) | MyTransform()

This code works but gives warning:

WARNING:root:This input type hint will be ignored and not used for type-checking purposes. Typically, input type hints for a PTransform are single (or nested) types wrapped by a PCollection, or PBegin. Got: Tuple[apache_beam.pvalue.PCollection[int], apache_beam.pvalue.PCollection[dict[str, typing.Any]]] instead.

I'd love to be able to give type hints that are actually used for type checking purposes.

I tried to reference beam.Flatten itself to see how it works, but sadly it doesn't use type hints at all.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745282108a4620336.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信