Skip to content

Commit 6d9df8c

Browse files
authored
Remove 3.9-specific branches in typehinting module (#36732)
* Remove 3.9-specific branches in typehinting module * linting
1 parent 87d204f commit 6d9df8c

File tree

4 files changed

+10
-22
lines changed

4 files changed

+10
-22
lines changed

sdks/python/apache_beam/typehints/native_type_compatibility.py

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

343341
# Unwrap Python 3.12 `type` aliases (TypeAliasType) to their underlying value.
@@ -368,7 +366,7 @@ def convert_to_beam_type(typ):
368366
# TODO(https://github.com/apache/beam/issues/19954): Currently unhandled.
369367
_LOGGER.info('Converting string literal type hint to Any: "%s"', typ)
370368
return typehints.Any
371-
elif sys.version_info >= (3, 10) and isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type
369+
elif isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type
372370
# Special case for NewType, where, since Python 3.10, NewType is now a class
373371
# rather than a function.
374372
# 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767

6868
import copy
6969
import logging
70-
import sys
7170
import types
7271
import typing
7372
from collections import abc
@@ -392,9 +391,8 @@ def validate_composite_type_param(type_param, error_msg_prefix):
392391
not isinstance(type_param, tuple(possible_classes)) and
393392
type_param is not None and
394393
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
394+
if isinstance(type_param, types.UnionType):
395+
is_not_type_constraint = False
398396

399397
if is_not_type_constraint:
400398
raise TypeError(

sdks/python/apache_beam/typehints/typehints_test.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import collections.abc
2323
import functools
2424
import re
25-
import sys
2625
import typing
2726
import unittest
2827

@@ -1929,12 +1928,11 @@ def expand(self, pcoll: typing.Any) -> typehints.Any:
19291928
def test_pipe_operator_as_union(self):
19301929
# union types can be written using pipe operator from Python 3.10.
19311930
# 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))
1931+
type_a = int | float # pylint: disable=unsupported-binary-operation
1932+
type_b = typing.Union[int, float]
1933+
self.assertEqual(
1934+
native_type_compatibility.convert_to_beam_type(type_a),
1935+
native_type_compatibility.convert_to_beam_type(type_b))
19381936

19391937

19401938
class TestNonBuiltInGenerics(unittest.TestCase):

0 commit comments

Comments
 (0)