Details
-
Improvement
-
Status: Resolved
-
P2
-
Resolution: Fixed
-
2.34.0
Description
Because the return type of the ptransform_fn is not specified, certain typecheckers will assume the type signature of functions decorated with it remain unchanged. However, ptransform_fn specifically adjusts the type signature such that the function no longer takes a pcoll.
This can be corrected by changing the the definition of ptransform_fn from:
def ptransform_fn(fn):
to:
def ptransform_fn(fn) -> Callable[..., _PTransformFnPTransform]:
This allows the typechecker to understand the return type of a function decorated with ptransform_fn will instead be a _PTransformFnPTransform type.
Additionally, for Python 3.10, ParamSpec could be used to preserve the signature of the internal function as well.
from typing import ParamSpec, TypeVar, Concatenate P = ParamSpec("P") T = TypeVar("T") R = TypeVar("R") def ptransform_fn(fn: Callable[Concatenate[PCollection[T], P], R]) -> Callable[[P], _PTransformFnPTransform]: ...
Attachments
Issue Links
- links to