[ 
https://issues.apache.org/jira/browse/BEAM-13439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17507084#comment-17507084
 ] 

Beam JIRA Bot commented on BEAM-13439:
--------------------------------------

This issue is P2 but has been unassigned without any comment for 60 days so it 
has been labeled "stale-P2". If this issue is still affecting you, we care! 
Please comment and remove the label. Otherwise, in 14 days the issue will be 
moved to P3.

Please see https://beam.apache.org/contribute/jira-priorities/ for a detailed 
explanation of what these priorities mean.


> Correct type signature on ptransform_fn to better support typecheckers
> ----------------------------------------------------------------------
>
>                 Key: BEAM-13439
>                 URL: https://issues.apache.org/jira/browse/BEAM-13439
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-py-core
>    Affects Versions: 2.34.0
>            Reporter: Sandy Chapman
>            Priority: P2
>              Labels: stale-P2, transform, typecheck
>          Time Spent: 4h 10m
>  Remaining Estimate: 0h
>
> Because the return type of the ptransform_fn is not specified, [certain 
> typecheckers|https://github.com/microsoft/pyright/issues/2688#issuecomment-990238720]
>  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:
> {code:python}
> def ptransform_fn(fn):
> {code}
> to:
> {code:python}
> def ptransform_fn(fn) -> Callable[..., _PTransformFnPTransform]: {code}
> 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|https://www.python.org/dev/peps/pep-0612/#parameter-specification-variables]
>  could be used to preserve the signature of the internal function as well.
> {code:python}
> 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]: ...{code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to