[
https://issues.apache.org/jira/browse/BEAM-10258?focusedWorklogId=451696&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-451696
]
ASF GitHub Bot logged work on BEAM-10258:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 26/Jun/20 19:23
Start Date: 26/Jun/20 19:23
Worklog Time Spent: 10m
Work Description: saavan-google-intern commented on a change in pull
request #12009:
URL: https://github.com/apache/beam/pull/12009#discussion_r446368663
##########
File path: sdks/python/apache_beam/typehints/typehints_test_py3.py
##########
@@ -46,11 +51,61 @@ class MyDoFn(DoFn):
def process(self, element: int) -> Iterable[str]:
pass
- print(MyDoFn().get_type_hints())
th = MyDoFn().get_type_hints()
self.assertEqual(th.input_types, ((int, ), {}))
self.assertEqual(th.output_types, ((str, ), {}))
+class TestPTransformAnnotations(unittest.TestCase):
+ def test_pep484_annotations(self):
+ class MyPTransform(PTransform):
+ def expand(self, pcoll: PCollection[int]) -> PCollection[str]:
+ return pcoll | Map(lambda num: str(num))
+
+ th = MyPTransform().get_type_hints()
+ self.assertEqual(th.input_types, ((int, ), {}))
+ self.assertEqual(th.output_types, ((str, ), {}))
+
+ def test_annotations_without_pcollection_wrapper(self):
+ class MyPTransform(PTransform):
+ def expand(self, pcoll: int) -> str:
+ return pcoll | Map(lambda num: str(num))
+
+ with self.assertRaises(TypeCheckError) as error:
+ _th = MyPTransform().get_type_hints()
+
+ self.assertEqual(str(error.exception), 'An input typehint to a PTransform
must be a single (or nested) type '
+ 'wrapped by a PCollection.')
+
+ def test_annotations_without_internal_type(self):
+ class MyPTransform(PTransform):
+ def expand(self, pcoll: PCollection) -> PCollection:
Review comment:
Thanks, fixed.
----------------------------------------------------------------
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: 451696)
Time Spent: 13h 20m (was: 13h 10m)
> Support type hint annotations on PTransform's expand()
> ------------------------------------------------------
>
> Key: BEAM-10258
> URL: https://issues.apache.org/jira/browse/BEAM-10258
> Project: Beam
> Issue Type: Improvement
> Components: sdk-py-core
> Reporter: Saavan Nanavati
> Assignee: Saavan Nanavati
> Priority: P2
> Time Spent: 13h 20m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)