Revert #38797
diff --git a/sdks/python/apache_beam/options/pipeline_options.py b/sdks/python/apache_beam/options/pipeline_options.py index c813939..41f9574 100644 --- a/sdks/python/apache_beam/options/pipeline_options.py +++ b/sdks/python/apache_beam/options/pipeline_options.py
@@ -889,15 +889,6 @@ action='store_true', help='Disable the use of beartype for type checking.') parser.add_argument( - '--exclude_infer_dataclass_field_type', - default=False, - action='store_true', - help='Exclude certain typehint inference involving dataclass fields ' - 'and resolve to Any (as in beam<=2.74.0). NOTE: this option is ' - 'for backward compatibility only and the exclusion scenarios are ' - 'subject to change or remove in a future version. For details see: ' - 'https://beam.apache.org/releases/pydoc/current/apache_beam.typehints.trivial_inference.html#apache_beam.typehints.trivial_inference.resolve_dataclass_field_type') # pylint: disable=line-too-long - parser.add_argument( '--runtime_type_check', default=False, action='store_true',
diff --git a/sdks/python/apache_beam/typehints/opcodes.py b/sdks/python/apache_beam/typehints/opcodes.py index 53eabda..963b5e0 100644 --- a/sdks/python/apache_beam/typehints/opcodes.py +++ b/sdks/python/apache_beam/typehints/opcodes.py
@@ -42,7 +42,6 @@ from apache_beam.typehints.trivial_inference import Const from apache_beam.typehints.trivial_inference import element_type from apache_beam.typehints.trivial_inference import key_value_types -from apache_beam.typehints.trivial_inference import resolve_dataclass_field_type from apache_beam.typehints.trivial_inference import union from apache_beam.typehints.typehints import Any from apache_beam.typehints.typehints import Dict @@ -452,9 +451,8 @@ elif inspect.isclass(o) and dataclasses.is_dataclass(o): field = o.__dataclass_fields__.get(name) if field is not None: - return resolve_dataclass_field_type(field.type) + return field.type return Any - else: return Any
diff --git a/sdks/python/apache_beam/typehints/trivial_inference.py b/sdks/python/apache_beam/typehints/trivial_inference.py index 69edfc3..68e126a 100644 --- a/sdks/python/apache_beam/typehints/trivial_inference.py +++ b/sdks/python/apache_beam/typehints/trivial_inference.py
@@ -774,29 +774,3 @@ if debug: print(f, id(f), input_types, '->', result) return result - - -def resolve_dataclass_field_type(x): - """ - Resolve a type to Beam typehint under global pipeline option context. - - Since Beam 2.75.0, typehints of dataclass fields are honored during type - inferences. However, in case of breakage (possible scenarios include - incorrect typehints; non-deterministic or nullable types disallowed by - consumer transform but check disabled by Any; tests rely on Any), - --exclude_infer_dataclass_field_type option to instruct falling back to Any. - Fields of builtin primitives are always respected. - """ - from apache_beam.options.pipeline_options_context import get_pipeline_options - options = get_pipeline_options() - if options: - from apache_beam.options.pipeline_options import TypeOptions - disabled = options.view_as(TypeOptions).exclude_infer_dataclass_field_type - else: - disabled = False - - if not disabled: - return typehints.normalize(x) - if x in (bool, bytes, complex, float, int, str): - return x - return Any
diff --git a/sdks/python/apache_beam/typehints/trivial_inference_test.py b/sdks/python/apache_beam/typehints/trivial_inference_test.py index dcb0bac..f421819 100644 --- a/sdks/python/apache_beam/typehints/trivial_inference_test.py +++ b/sdks/python/apache_beam/typehints/trivial_inference_test.py
@@ -24,8 +24,6 @@ import unittest import apache_beam as beam -from apache_beam.options.pipeline_options import PipelineOptions -from apache_beam.options.pipeline_options_context import scoped_pipeline_options from apache_beam.typehints import row_type from apache_beam.typehints import trivial_inference from apache_beam.typehints import typehints @@ -492,27 +490,14 @@ def testDataClassFields(self): @dataclasses.dataclass - class BaseClass: - pass - - @dataclasses.dataclass class MyDataClass: id: int name: str - tags: list[str] - custom: BaseClass self.assertReturnType( - typehints.Tuple[int, str, typehints.List[str], BaseClass], - python_callable.PythonCallableWithSource( - "lambda x: (x.id, x.name, x.tags, x.custom)"), [MyDataClass]) - - options = PipelineOptions(['--exclude_infer_dataclass_field_type']) - with scoped_pipeline_options(options): - self.assertReturnType( - typehints.Tuple[int, str, typehints.Any, typehints.Any], - python_callable.PythonCallableWithSource( - "lambda x: (x.id, x.name, x.tags, x.custom)"), [MyDataClass]) + typehints.Tuple[int, str], + python_callable.PythonCallableWithSource("lambda x: (x.id, x.name)"), + [MyDataClass]) if __name__ == '__main__':
diff --git a/sdks/python/apache_beam/typehints/typehints.py b/sdks/python/apache_beam/typehints/typehints.py index ffef40d..6dc88a9 100644 --- a/sdks/python/apache_beam/typehints/typehints.py +++ b/sdks/python/apache_beam/typehints/typehints.py
@@ -1453,7 +1453,6 @@ def normalize(x, none_as_type=False): - """Normalize a type to Beam typehint.""" # None is inconsistantly used for Any, unknown, or NoneType. # Avoid circular imports
diff --git a/sdks/python/setup.py b/sdks/python/setup.py index b8fd2f5..aabe039 100644 --- a/sdks/python/setup.py +++ b/sdks/python/setup.py
@@ -526,10 +526,7 @@ 'google-api-core>=2.0.0,<3', 'google-apitools>=0.5.31,<0.5.32; python_version < "3.13"', 'google-apitools>=0.5.35; python_version >= "3.13"', - # NOTE: Maintainers, please do not require google-auth>=2.x.x - # Until this issue is closed - # https://github.com/googleapis/google-cloud-python/issues/10566 - 'google-auth>=1.18.0,<3', + 'google-auth>=2.0.0,<3', 'google-auth-httplib2>=0.1.0,<0.3.0', 'google-cloud-datastore>=2.0.0,<3', 'google-cloud-pubsub>=2.1.0,<3',