Skip to content

Commit f673d67

Browse files
committed
Add back sys import.
1 parent 534e1cb commit f673d67

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sdks/python/apache_beam/typehints/native_type_compatibility.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import collections
2323
import collections.abc
2424
import logging
25+
import sys
2526
import types
2627
import typing
2728
from typing import Generic
@@ -335,7 +336,8 @@ def convert_to_beam_type(typ):
335336
# pipe operator as Union and types.UnionType are introduced
336337
# in Python 3.10.
337338
# GH issue: https://github.com/apache/beam/issues/21972
338-
if isinstance(typ, types.UnionType):
339+
if (sys.version_info.major == 3 and
340+
sys.version_info.minor >= 10) and (isinstance(typ, types.UnionType)):
339341
typ = typing.Union[typ]
340342

341343
# Unwrap Python 3.12 `type` aliases (TypeAliasType) to their underlying value.
@@ -366,7 +368,7 @@ def convert_to_beam_type(typ):
366368
# TODO(https://github.com/apache/beam/issues/19954): Currently unhandled.
367369
_LOGGER.info('Converting string literal type hint to Any: "%s"', typ)
368370
return typehints.Any
369-
elif isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type
371+
elif sys.version_info >= (3, 10) and isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type
370372
# Special case for NewType, where, since Python 3.10, NewType is now a class
371373
# rather than a function.
372374
# TODO(https://github.com/apache/beam/issues/20076): Currently unhandled.

0 commit comments

Comments
 (0)