You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Danny McCormick (Jira)" <ji...@apache.org> on 2022/06/04 20:51: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=17549384#comment-17549384 ]
Danny McCormick commented on BEAM-12457:
----------------------------------------
This issue has been migrated to https://github.com/apache/beam/issues/20986
> 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: P3
>
> 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.20.7#820007)