title: How to properly type beam.Map with pyright
body: <p>I have beam code like:</p>
  <pre class="lang-py prettyprint-override"><code>
  def foo(i: int) -&gt; Foo:
    ...
  class IntToFoo(beam.PTransform):
    def expand(self, pcoll: PCollection[int]) -&gt; PCollection[Foo]:
      return pcoll | beam.Map(foo)
  </code></pre>
  <p>Running <em>pyright</em> it complains for the returning line:</p>
  <pre><code>Expression of type &quot;PValue&quot; cannot be assigned to return type &quot;PCollection[Foo]&quot;
    &quot;PValue&quot; is incompatible with &quot;PCollection[Foo]
  </code></pre>
  <p>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).</p>
  <p><strong>EDIT</strong>:</p>
  <p>I now tried:</p>
  <pre class="lang-py prettyprint-override"><code>    temp = pcoll | beam.Map(foo)
      assert isinstance(temp, PCollection[Foo])
      return temp
  </code></pre>
  <p>Good news is, neither <code>temp =</code> nor <code>return</code> line has any errors. Bad news is that it complains on isinstance line now:</p>
  <blockquote>
  <p>TypeVar or generic type with type arguments not allowed</p>
  </blockquote>
  <p><strong>EDIT 2</strong>:</p>
  <p>For now I settled with</p>
  <pre class="lang-py prettyprint-override"><code>temp = pcoll | beam.Map(foo)
  return cast(PCollection[Foo], temp)
  </code></pre>
  <p>which IMO is still not a solution, because I then would need to specify <code>PCollection[Foo]</code> both the signature as well as the cast.</p>