You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Beam JIRA Bot (Jira)" <ji...@apache.org> on 2021/08/06 17:22:00 UTC

[jira] [Commented] (BEAM-12457) beam crash when annotating function with typing.Protocol

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

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

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.


> beam crash when annotating function with typing.Protocol
> --------------------------------------------------------
>
>                 Key: BEAM-12457
>                 URL: https://issues.apache.org/jira/browse/BEAM-12457
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-py-core
>    Affects Versions: 2.29.0, 2.31.0
>            Reporter: Etienne POT
>            Priority: P2
>              Labels: stale-P2
>
> When annotating a function with a https://docs.python.org/3/library/typing.html#typing.Protocol:
> {code:python}
> class Data(typing.Protocol):
>     def f(self) -> int:
>         ...
> def fn(x: Data) -> Data:
>   ...
> pipeline = (
>    ...
>    | beam.Map(fn)
>    ...
> )
> {code}
> Beam will crash when `pipeline_type_check=True` because isinstance(x, Data) raise an error.
> Indeed, by default, Protocol are not runtime checkable.
> ```
> {noformat}
>   File "/usr/local/google/_blaze_epot/e52e0fa21f849d3c6badad5aaa8158a8/execroot/google3/blaze-out/k8-fastbuild/bin/third_party/py/tensorflow_datasets/scripts/tools/compute_split_info.runfiles/google3/third_party/py/apache_beam/transforms/ptransform.py", line 935, in type_check_inputs
>     hint):
>   File "/usr/local/google/_blaze_epot/e52e0fa21f849d3c6badad5aaa8158a8/execroot/google3/blaze-out/k8-fastbuild/bin/third_party/py/tensorflow_datasets/scripts/tools/compute_split_info.runfiles/google3/third_party/py/apache_beam/typehints/typehints.py", line 1172, in is_consistent_with
>     return issubclass(sub, base)
>   File "/usr/local/google/_blaze_epot/e52e0fa21f849d3c6badad5aaa8158a8/execroot/google3/blaze-out/k8-fastbuild/bin/third_party/py/tensorflow_datasets/scripts/tools/compute_split_info.runfiles/google3/third_party/py/typing_extensions/src_py3/typing_extensions.py", line 1265, in __subclasscheck__
>     raise TypeError("Instance and class checks can only be used with"
> TypeError: Instance and class checks can only be used with @runtime protocols
> {noformat}
> ```
> Even if protocol are not runtime checkable, this is a perfectly valid python annotation, so beam should not raise error. For example, beam could ignore the annotation if isinstance raise error



--
This message was sent by Atlassian Jira
(v8.3.4#803005)