[ https://issues.apache.org/jira/browse/BEAM-7060?focusedWorklogId=304680&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-304680 ]
ASF GitHub Bot logged work on BEAM-7060: ---------------------------------------- Author: ASF GitHub Bot Created on: 31/Aug/19 00:21 Start Date: 31/Aug/19 00:21 Worklog Time Spent: 10m Work Description: udim commented on pull request #9283: [BEAM-7060] Type hints from Python 3 annotations URL: https://github.com/apache/beam/pull/9283#discussion_r319691656 ########## File path: sdks/python/apache_beam/typehints/typed_pipeline_test.py ########## @@ -290,5 +306,26 @@ def test_flat_type_hint(self): self.test_input | self.CustomTransform().with_output_types(int) +class AnnotationsTest(unittest.TestCase): + + def test_pardo_wrapper_builtin(self): + th = beam.ParDo(str.strip).get_type_hints() + if sys.version_info < (3, 7): + self.assertEqual(th.input_types, ((str,), {})) + else: + # Python 3.7+ has annotations for CPython builtins + # (_MethodDescriptorType). + self.assertEqual(th.input_types, ((str, typehints.Any), {})) + self.assertEqual(th.output_types, ((typehints.Any,), {})) + + th = beam.ParDo(list).get_type_hints() + self.assertIsNone(th.input_types) + self.assertIsNone(th.output_types) Review comment: Added inference of return types for callables that are instances of `type`. Removed below test case for `len`, since it doesn't return a valid iterable (couldn't find another 'builtin_function_or_method' to replace it with, see typed_pipeline_test_py3.py for cases where we raise a ValueError if return type annotation is not iterable). ---------------------------------------------------------------- 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: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 304680) Time Spent: 13h (was: 12h 50m) > Design Py3-compatible typehints annotation support in Beam 3. > ------------------------------------------------------------- > > Key: BEAM-7060 > URL: https://issues.apache.org/jira/browse/BEAM-7060 > Project: Beam > Issue Type: Sub-task > Components: sdk-py-core > Reporter: Valentyn Tymofieiev > Assignee: Udi Meiri > Priority: Major > Fix For: 2.16.0 > > Time Spent: 13h > Remaining Estimate: 0h > > Existing [Typehints implementaiton in > Beam|[https://github.com/apache/beam/blob/master/sdks/python/apache_beam/typehints/ > ] heavily relies on internal details of CPython implementation, and some of > the assumptions of this implementation broke as of Python 3.6, see for > example: https://issues.apache.org/jira/browse/BEAM-6877, which makes > typehints support unusable on Python 3.6 as of now. [Python 3 Kanban > Board|https://issues.apache.org/jira/secure/RapidBoard.jspa?rapidView=245&view=detail] > lists several specific typehints-related breakages, prefixed with "TypeHints > Py3 Error". > We need to decide whether to: > - Deprecate in-house typehints implementation. > - Continue to support in-house implementation, which at this point is a stale > code and has other known issues. > - Attempt to use some off-the-shelf libraries for supporting > type-annotations, like Pytype, Mypy, PyAnnotate. > WRT to this decision we also need to plan on immediate next steps to unblock > adoption of Beam for Python 3.6+ users. One potential option may be to have > Beam SDK ignore any typehint annotations on Py 3.6+. > cc: [~udim], [~altay], [~robertwb]. -- This message was sent by Atlassian Jira (v8.3.2#803003)