[
https://issues.apache.org/jira/browse/BEAM-13439?focusedWorklogId=721389&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-721389
]
ASF GitHub Bot logged work on BEAM-13439:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 05/Feb/22 06:04
Start Date: 05/Feb/22 06:04
Worklog Time Spent: 10m
Work Description: tvalentyn commented on a change in pull request #16517:
URL: https://github.com/apache/beam/pull/16517#discussion_r800006634
##########
File path: sdks/python/apache_beam/transforms/ptransform.py
##########
@@ -1002,7 +1002,7 @@ def default_label(self):
return label_from_callable(self._fn)
-def ptransform_fn(fn):
+def ptransform_fn(fn) -> Callable[..., _PTransformFnPTransform]:
Review comment:
We currently use annotations with explicit `# type:` comment in
annotations. We added them back when still supporting Python 2, and planned a
rewrite into native Py3 type hints, but looks like that didn't land yet.
For consistency reasons, could you please you try the old style annotation
and see if that works for your purposes, @SandyChapman ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 721389)
Time Spent: 1h (was: 50m)
> 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: transform, typecheck
> Time Spent: 1h
> 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)