[
https://issues.apache.org/jira/browse/BEAM-8489?focusedWorklogId=352994&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-352994
]
ASF GitHub Bot logged work on BEAM-8489:
----------------------------------------
Author: ASF GitHub Bot
Created on: 03/Dec/19 21:23
Start Date: 03/Dec/19 21:23
Worklog Time Spent: 10m
Work Description: udim commented on pull request #9890: [BEAM-8489]
Filter: don't use callable's output type
URL: https://github.com/apache/beam/pull/9890#discussion_r353428777
##########
File path: sdks/python/apache_beam/transforms/core.py
##########
@@ -1544,10 +1544,16 @@ def Filter(fn, *args, **kwargs): # pylint:
disable=invalid-name
# TODO: What about callable classes?
if hasattr(fn, '__name__'):
wrapper.__name__ = fn.__name__
+
+ # Get type hints from this instance or the callable. Do not use output type
+ # hints from the callable (which should be bool if set).
+ fn_type_hints = typehints.decorators.IOTypeHints.from_callable(fn)
+ if fn_type_hints is not None:
+ fn_type_hints.output_types = None
Review comment:
After this PR, output_hint is set from one of (in order):
- fn._type_hints.output_types[0][0] (could be set using the
with_output_types() decorator)
- fn._type_hints.input_types[0][0]
- IOTypeHints.from_callable(fn).input_types[0][0] (Py3 type hint syntax)
This change removes IOTypeHints.from_callable(fn).output_types[0][0] from
the above list.
To answer your question, the branches are still required. The branch in line
1559 checks if output_hint is None and tries using input_types as a substitute.
But output_hint may still remain None so line 1563 avoids setting an output
type of Iterable[None].
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 352994)
Time Spent: 40m (was: 0.5h)
> Python typehints: filter callable output type hint should not be used
> ---------------------------------------------------------------------
>
> Key: BEAM-8489
> URL: https://issues.apache.org/jira/browse/BEAM-8489
> Project: Beam
> Issue Type: Bug
> Components: sdk-py-core
> Reporter: Udi Meiri
> Assignee: Udi Meiri
> Priority: Major
> Time Spent: 40m
> Remaining Estimate: 0h
>
> A filter function returns bool, while the Filter() transform outputs the same
> element type as the input.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)