diff --git a/sdks/python/apache_beam/transforms/core.py b/sdks/python/apache_beam/transforms/core.py index b5c3178210d9..4e026369c526 100644 --- a/sdks/python/apache_beam/transforms/core.py +++ b/sdks/python/apache_beam/transforms/core.py @@ -2456,10 +2456,9 @@ def expand(self, pcoll): tagged_type_hints = dict(self._fn.get_type_hints().tagged_output_types()) # Dead letter format: Tuple[element, Tuple[exception_type, repr, traceback]] - dead_letter_type = typehints.Tuple[pcoll.element_type, - typehints.Tuple[type, - str, - typehints.List[str]]] + dead_letter_type = typehints.Tuple[ + pcoll.element_type, + typehints.Tuple[type[typing.Any], str, typehints.Sequence[str]]] tagged_type_hints[self._dead_letter_tag] = dead_letter_type pardo = pardo.with_output_types(main_output_type, **tagged_type_hints) diff --git a/sdks/python/apache_beam/transforms/core_test.py b/sdks/python/apache_beam/transforms/core_test.py index d80a03bdf53b..f42ab1d2549c 100644 --- a/sdks/python/apache_beam/transforms/core_test.py +++ b/sdks/python/apache_beam/transforms/core_test.py @@ -22,6 +22,7 @@ import os import tempfile import unittest +from typing import Any from typing import Iterable from typing import Literal from typing import TypeVar @@ -561,7 +562,7 @@ def test_with_exception_handling_then_with_outputs(self): self.assertEqual(results.fives.element_type, str) self.assertEqual( results.bad.element_type, - typehints.Tuple[int, typehints.Tuple[type, str, typehints.List[str]]]) + typehints.Tuple[int, typehints.Tuple[type[Any], str, typehints.Sequence[str]]]) def test_with_outputs_then_with_exception_handling(self): """Direction 2: .with_outputs().with_exception_handling()""" @@ -584,7 +585,7 @@ def test_with_outputs_then_with_exception_handling(self): self.assertEqual(results.fives.element_type, str) self.assertEqual( results.bad.element_type, - typehints.Tuple[int, typehints.Tuple[type, str, typehints.List[str]]]) + typehints.Tuple[int, typehints.Tuple[type[Any], str, typehints.Sequence[str]]]) def test_with_outputs_then_with_exception_handling_custom_dead_letter_tag( self): @@ -605,7 +606,7 @@ def test_with_outputs_then_with_exception_handling_custom_dead_letter_tag( self.assertEqual(results.threes.element_type, int) self.assertEqual( results.errors.element_type, - typehints.Tuple[int, typehints.Tuple[type, str, typehints.List[str]]]) + typehints.Tuple[int, typehints.Tuple[type[Any], str, typehints.Sequence[str]]]) def test_with_exception_handling_then_with_outputs_custom_dead_letter_tag( self): @@ -626,7 +627,7 @@ def test_with_exception_handling_then_with_outputs_custom_dead_letter_tag( self.assertEqual(results.threes.element_type, int) self.assertEqual( results.errors.element_type, - typehints.Tuple[int, typehints.Tuple[type, str, typehints.List[str]]]) + typehints.Tuple[int, typehints.Tuple[type[Any], str, typehints.Sequence[str]]]) def test_exception_handling_no_with_outputs_backward_compat(self): """Without with_outputs(), behavior is unchanged."""