You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Udi Meiri (Jira)" <ji...@apache.org> on 2020/02/24 22:19:00 UTC
[jira] [Commented] (BEAM-9377) Python typehints: Map wrapper
prevents Optional stripping
[ https://issues.apache.org/jira/browse/BEAM-9377?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17043916#comment-17043916 ]
Udi Meiri commented on BEAM-9377:
---------------------------------
Currently, Optional is only stripped when it's the outermost element of the output hint.
This needs careful examination, but it may be correct to strip Optional before and/or after Iterable, e.g. Optional[Iterable[Optional[int]]] =>(to ParDo output type) int.
cc: [~robertwb]
> Python typehints: Map wrapper prevents Optional stripping
> ---------------------------------------------------------
>
> Key: BEAM-9377
> URL: https://issues.apache.org/jira/browse/BEAM-9377
> Project: Beam
> Issue Type: New Feature
> Components: sdk-py-core
> Reporter: Udi Meiri
> Priority: Major
>
> This existing test is wrong:
> {code}
> def test_map_wrapper_optional_output(self):
> # Optional does affect output type (Nones are NOT ignored).
> def map_fn(unused_element: int) -> typehints.Optional[int]:
> return 1
> th = beam.Map(map_fn).get_type_hints()
> self.assertEqual(th.input_types, ((int, ), {}))
> self.assertEqual(th.output_types, ((typehints.Optional[int], ), {}))
> {code}
> The resulting output type should be int.
> {code}
> inital output hint:
> Optional[int]
> with wrapper:
> Iterable[Optional[int]]
> with DoFn.default_type_hints:
> Optional[int]
> {code}
> However any Nones returned by a DoFn's process method are dropped, so the actual element_type returned is plain int.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)