I have beam code like:
def foo(i: int) -> Foo:
...
class IntToFoo(beam.PTransform):
def expand(self, pcoll: PCollection[int]) -> PCollection[Foo]:
return pcoll | beam.Map(foo)
Running pyright it complains for the returning line:
Expression of type "PValue" cannot be assigned to return type "PCollection[Foo]"
"PValue" is incompatible with "PCollection[Foo]
Now AFAIU it seems like beam does not provide sufficient type hinting. Is there a way of working around that as a user of beam so that pyright accepts the code (without ignoring the type error).
EDIT:
I now tried:
temp = pcoll | beam.Map(foo)
assert isinstance(temp, PCollection[Foo])
return temp
Good news is, neither temp =
nor return
line has any errors. Bad news is that it complains on isinstance line now:
TypeVar or generic type with type arguments not allowed
EDIT 2:
For now I settled with
temp = pcoll | beam.Map(foo)
return cast(PCollection[Foo], temp)
which IMO is still not a solution, because I then would need to specify PCollection[Foo]
both the signature as well as the cast.