Gaurav598 commented on code in PR #40625:
URL: https://github.com/apache/beam/pull/40625#discussion_r4290882759
##########
sdks/python/apache_beam/typehints/decorators_test.py:
##########
@@ -256,6 +256,51 @@ def fn(
}))
self.assertEqual(th.output_types, ((Tuple[Any, ...], ), {}))
+ def test_from_callable_resolves_string_annotations(self):
+ def fn(value: 'int') -> 'typehints.List[str]':
+ return [str(value)]
+
+ th = decorators.IOTypeHints.from_callable(fn)
+ self.assertEqual(th.input_types, ((int, ), {}))
+ self.assertEqual(th.output_types, ((List[str], ), {}))
+
+ def test_from_callable_resolves_future_annotations(self):
+ namespace = {'typehints': typehints}
+ exec(
+ 'from __future__ import annotations\n'
+ 'def fn(value: int) -> typehints.List[str]:\n'
+ ' return [str(value)]\n', namespace)
+
+ th = decorators.IOTypeHints.from_callable(namespace['fn'])
+ self.assertEqual(th.input_types, ((int, ), {}))
+ self.assertEqual(th.output_types, ((List[str], ), {}))
+
+ def test_from_callable_resolves_class_constructor_string_annotations(self):
+ class Class(object):
+ def __init__(self, value: 'int'):
+ self.value = value
+
+ th = decorators.IOTypeHints.from_callable(Class)
+ self.assertEqual(th.input_types, ((int, ), {}))
+ self.assertEqual(th.output_types, ((Class, ), {}))
+
+ def test_from_callable_resolves_method_string_annotations(self):
+ class Class(object):
+ def process(self, value: 'int') -> 'typehints.List[str]':
+ return [str(value)]
+
+ th = decorators.IOTypeHints.from_callable(Class().process)
+ self.assertEqual(th.input_types, ((int, ), {}))
+ self.assertEqual(th.output_types, ((List[str], ), {}))
+
+ def test_from_callable_unresolved_string_annotations_fall_back_to_any(self):
+ def fn(value: 'MissingType') -> 'int':
+ return 1
+
+ th = decorators.IOTypeHints.from_callable(fn)
+ self.assertEqual(th.input_types, ((Any, ), {}))
+ self.assertEqual(th.output_types, ((Any, ), {}))
Review Comment:
Fixed in `8e46db4`.
The test now expects the unresolved `MissingType` input to fall back to
`Any`, while the independently resolvable `'int'` return annotation resolves to
`int`. Added additional mixed-resolution coverage.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]