Skip to content

Commit 16a1822

Browse files
committed
Remove 3.9-specific branches in typehinting module
1 parent 2d617c0 commit 16a1822

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

sdks/python/apache_beam/typehints/native_type_compatibility.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ def convert_to_beam_type(typ):
328328
# pipe operator as Union and types.UnionType are introduced
329329
# in Python 3.10.
330330
# GH issue: https://github.com/apache/beam/issues/21972
331-
if (sys.version_info.major == 3 and
332-
sys.version_info.minor >= 10) and (isinstance(typ, types.UnionType)):
331+
if isinstance(typ, types.UnionType):
333332
typ = typing.Union[typ]
334333

335334
if getattr(typ, '__module__', None) == 'typing':
@@ -352,7 +351,7 @@ def convert_to_beam_type(typ):
352351
# TODO(https://github.com/apache/beam/issues/19954): Currently unhandled.
353352
_LOGGER.info('Converting string literal type hint to Any: "%s"', typ)
354353
return typehints.Any
355-
elif sys.version_info >= (3, 10) and isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type
354+
elif isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type
356355
# Special case for NewType, where, since Python 3.10, NewType is now a class
357356
# rather than a function.
358357
# TODO(https://github.com/apache/beam/issues/20076): Currently unhandled.

sdks/python/apache_beam/typehints/trivial_inference.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,7 @@ def infer_return_type_func(f, input_types, debug=False, depth=0):
394394
inst_size = 2
395395
opt_arg_size = 0
396396

397-
# Python 3.10: bpo-27129 changes jump offsets to use instruction offsets,
398-
# not byte offsets. The offsets were halved (16 bits fro instructions vs 8
399-
# bits for bytes), so we have to double the value of arg.
400-
if (sys.version_info.major, sys.version_info.minor) >= (3, 10):
401-
jump_multiplier = 2
402-
else:
403-
jump_multiplier = 1
397+
jump_multiplier = 2
404398

405399
last_pc = -1
406400
last_real_opname = opname = None

sdks/python/apache_beam/typehints/typehints.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,8 @@ def validate_composite_type_param(type_param, error_msg_prefix):
392392
not isinstance(type_param, tuple(possible_classes)) and
393393
type_param is not None and
394394
getattr(type_param, '__module__', None) != 'typing')
395-
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
396-
if isinstance(type_param, types.UnionType):
397-
is_not_type_constraint = False
395+
if isinstance(type_param, types.UnionType):
396+
is_not_type_constraint = False
398397

399398
if is_not_type_constraint:
400399
raise TypeError(

sdks/python/apache_beam/typehints/typehints_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,12 +1929,11 @@ def expand(self, pcoll: typing.Any) -> typehints.Any:
19291929
def test_pipe_operator_as_union(self):
19301930
# union types can be written using pipe operator from Python 3.10.
19311931
# https://peps.python.org/pep-0604/
1932-
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
1933-
type_a = int | float # pylint: disable=unsupported-binary-operation
1934-
type_b = typing.Union[int, float]
1935-
self.assertEqual(
1936-
native_type_compatibility.convert_to_beam_type(type_a),
1937-
native_type_compatibility.convert_to_beam_type(type_b))
1932+
type_a = int | float # pylint: disable=unsupported-binary-operation
1933+
type_b = typing.Union[int, float]
1934+
self.assertEqual(
1935+
native_type_compatibility.convert_to_beam_type(type_a),
1936+
native_type_compatibility.convert_to_beam_type(type_b))
19381937

19391938

19401939
class TestNonBuiltInGenerics(unittest.TestCase):

0 commit comments

Comments
 (0)