From f673d671934b7e9331b94c686e8e51387d1272a4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 19 Nov 2025 10:34:50 -0500 Subject: [PATCH 1/2] Add back sys import. --- .../apache_beam/typehints/native_type_compatibility.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index 637574ce837e..2360df142167 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -22,6 +22,7 @@ import collections import collections.abc import logging +import sys import types import typing from typing import Generic @@ -335,7 +336,8 @@ def convert_to_beam_type(typ): # pipe operator as Union and types.UnionType are introduced # in Python 3.10. # GH issue: https://github.com/apache/beam/issues/21972 - if isinstance(typ, types.UnionType): + if (sys.version_info.major == 3 and + sys.version_info.minor >= 10) and (isinstance(typ, types.UnionType)): typ = typing.Union[typ] # Unwrap Python 3.12 `type` aliases (TypeAliasType) to their underlying value. @@ -366,7 +368,7 @@ def convert_to_beam_type(typ): # TODO(https://github.com/apache/beam/issues/19954): Currently unhandled. _LOGGER.info('Converting string literal type hint to Any: "%s"', typ) return typehints.Any - elif isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type + elif sys.version_info >= (3, 10) and isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type # Special case for NewType, where, since Python 3.10, NewType is now a class # rather than a function. # TODO(https://github.com/apache/beam/issues/20076): Currently unhandled. From 01d3cd3a24bbaf512e21bd0fb3e9f517f9193a27 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 19 Nov 2025 10:38:48 -0500 Subject: [PATCH 2/2] mend --- .../apache_beam/typehints/native_type_compatibility.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index 2360df142167..7cdfa0721ffa 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -336,8 +336,7 @@ def convert_to_beam_type(typ): # pipe operator as Union and types.UnionType are introduced # in Python 3.10. # GH issue: https://github.com/apache/beam/issues/21972 - if (sys.version_info.major == 3 and - sys.version_info.minor >= 10) and (isinstance(typ, types.UnionType)): + if isinstance(typ, types.UnionType): typ = typing.Union[typ] # Unwrap Python 3.12 `type` aliases (TypeAliasType) to their underlying value. @@ -368,7 +367,7 @@ def convert_to_beam_type(typ): # TODO(https://github.com/apache/beam/issues/19954): Currently unhandled. _LOGGER.info('Converting string literal type hint to Any: "%s"', typ) return typehints.Any - elif sys.version_info >= (3, 10) and isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type + elif isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type # Special case for NewType, where, since Python 3.10, NewType is now a class # rather than a function. # TODO(https://github.com/apache/beam/issues/20076): Currently unhandled.