From e6e66f70324eef595cd87b322cce535b758d9106 Mon Sep 17 00:00:00 2001 From: Udi Meiri Date: Wed, 18 Sep 2019 17:40:26 -0700 Subject: [PATCH] [BEAM-8279] Disable IOTypeHints.from_callable --- sdks/python/apache_beam/typehints/decorators.py | 4 ++++ sdks/python/apache_beam/typehints/decorators_test.py | 2 ++ sdks/python/apache_beam/typehints/decorators_test_py3.py | 1 + sdks/python/apache_beam/typehints/typed_pipeline_test.py | 3 +++ sdks/python/apache_beam/typehints/typed_pipeline_test_py3.py | 3 +++ sdks/python/apache_beam/typehints/typehints_test_py3.py | 3 +++ 6 files changed, 16 insertions(+) diff --git a/sdks/python/apache_beam/typehints/decorators.py b/sdks/python/apache_beam/typehints/decorators.py index 69c77e45d5ed..fdd38495acec 100644 --- a/sdks/python/apache_beam/typehints/decorators.py +++ b/sdks/python/apache_beam/typehints/decorators.py @@ -121,6 +121,8 @@ def foo((a, b)): _ANY_VAR_POSITIONAL = typehints.Tuple[typehints.Any, ...] _ANY_VAR_KEYWORD = typehints.Dict[typehints.Any, typehints.Any] +# TODO(BEAM-8280): Remove this when from_callable is ready to be enabled. +_enable_from_callable = False try: _original_getfullargspec = inspect.getfullargspec @@ -229,6 +231,8 @@ def from_callable(fn): Returns: A new IOTypeHints or None if no annotations found. """ + if not _enable_from_callable: + return None signature = get_signature(fn) if (all(param.annotation == param.empty for param in signature.parameters.values()) diff --git a/sdks/python/apache_beam/typehints/decorators_test.py b/sdks/python/apache_beam/typehints/decorators_test.py index 995826830f47..645fae6cd8ca 100644 --- a/sdks/python/apache_beam/typehints/decorators_test.py +++ b/sdks/python/apache_beam/typehints/decorators_test.py @@ -27,6 +27,8 @@ from apache_beam.typehints import WithTypeHints from apache_beam.typehints import decorators +decorators._enable_from_callable = True + class IOTypeHintsTest(unittest.TestCase): diff --git a/sdks/python/apache_beam/typehints/decorators_test_py3.py b/sdks/python/apache_beam/typehints/decorators_test_py3.py index 84e0a00dcffa..7659a726de22 100644 --- a/sdks/python/apache_beam/typehints/decorators_test_py3.py +++ b/sdks/python/apache_beam/typehints/decorators_test_py3.py @@ -28,6 +28,7 @@ from apache_beam.typehints import TypeVariable from apache_beam.typehints import decorators +decorators._enable_from_callable = True T = TypeVariable('T') diff --git a/sdks/python/apache_beam/typehints/typed_pipeline_test.py b/sdks/python/apache_beam/typehints/typed_pipeline_test.py index 82c4a63c4225..2e39a60f9574 100644 --- a/sdks/python/apache_beam/typehints/typed_pipeline_test.py +++ b/sdks/python/apache_beam/typehints/typed_pipeline_test.py @@ -31,12 +31,15 @@ from apache_beam.testing.util import assert_that from apache_beam.testing.util import equal_to from apache_beam.typehints import WithTypeHints +from apache_beam.typehints import decorators from apache_beam.typehints.decorators import get_signature # These test often construct a pipeline as value | PTransform to test side # effects (e.g. errors). # pylint: disable=expression-not-assigned +decorators._enable_from_callable = True + class MainInputTest(unittest.TestCase): diff --git a/sdks/python/apache_beam/typehints/typed_pipeline_test_py3.py b/sdks/python/apache_beam/typehints/typed_pipeline_test_py3.py index e4575bf9bda4..1c0c66c9a8b4 100644 --- a/sdks/python/apache_beam/typehints/typed_pipeline_test_py3.py +++ b/sdks/python/apache_beam/typehints/typed_pipeline_test_py3.py @@ -24,6 +24,9 @@ import apache_beam as beam from apache_beam import typehints +from apache_beam.typehints import decorators + +decorators._enable_from_callable = True class MainInputTest(unittest.TestCase): diff --git a/sdks/python/apache_beam/typehints/typehints_test_py3.py b/sdks/python/apache_beam/typehints/typehints_test_py3.py index 0ffa86c5cdd8..01df57cdca8b 100644 --- a/sdks/python/apache_beam/typehints/typehints_test_py3.py +++ b/sdks/python/apache_beam/typehints/typehints_test_py3.py @@ -26,6 +26,9 @@ from apache_beam.transforms.core import DoFn from apache_beam.typehints import KV from apache_beam.typehints import Iterable +from apache_beam.typehints import decorators + +decorators._enable_from_callable = True class TestParDoAnnotations(unittest.TestCase):