From 9c422f1523c9f53a3f267a3730ffe7fd283cabcc Mon Sep 17 00:00:00 2001 From: "labs-code-app[bot]" <161369871+labs-code-app[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:28:19 +0000 Subject: [PATCH 1/8] Refactor: Add convert_collections_from_typing() Added to convert typing module collections to built-ins. This function effectively reverses the operation of the function. Includes comprehensive unit tests to verify the correct conversion of various typing collections to their builtin counterparts, including nested structures and type variables. --- .../typehints/native_type_compatibility.py | 24 +++++++++++++++ .../native_type_compatibility_test.py | 30 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index 381d4f7aae2b..f2b6721f8d76 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -472,6 +472,30 @@ def convert_to_typing_type(typ): raise ValueError('Failed to convert Beam type: %s' % typ) +def convert_collections_from_typing(typ): + """Converts a given typing collections type to its builtin counterpart. + + Args: + typ: A typing type (e.g., typing.List[int]). + + Returns: + type: The corresponding builtin type (e.g., list). + """ + origin = getattr(typ, '__origin__', None) + if origin is typing.List: + return list[convert_to_typing_type(typ.__args__[0])] + elif origin is typing.Dict: + return dict[convert_to_typing_type(typ.__args__[0]), convert_to_typing_type(typ.__args__[1])] + elif origin is typing.Tuple: + return tuple[tuple(convert_to_typing_types(typ.__args__))] + elif origin is typing.Set: + return set[convert_to_typing_type(typ.__args__[0])] + elif origin is typing.FrozenSet: + return frozenset[convert_to_typing_type(typ.__args__[0])] + else: + return typ + + def convert_to_typing_types(args): """Convert the given list or dictionary of args to typing types. diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py index ae8e1a0b2906..02cfe3287c3e 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py @@ -30,7 +30,7 @@ from apache_beam.typehints.native_type_compatibility import convert_to_beam_types from apache_beam.typehints.native_type_compatibility import convert_to_typing_type from apache_beam.typehints.native_type_compatibility import convert_to_typing_types -from apache_beam.typehints.native_type_compatibility import is_any +from apache_beam.typehints.native_type_compatibility import convert_collections_from_typing, is_any _TestNamedTuple = typing.NamedTuple( '_TestNamedTuple', [('age', int), ('name', bytes)]) @@ -43,6 +43,7 @@ class _TestClass(object): T = typing.TypeVar('T') +U = typing.TypeVar('U') class _TestGeneric(typing.Generic[T]): @@ -337,6 +338,33 @@ def test_is_any(self): for expected, typ in test_cases: self.assertEqual(expected, is_any(typ), msg='%s' % typ) + def test_convert_collections_from_typing(self): + test_cases = [ + ('list', typing.List[int], list[int]), + ('dict', typing.Dict[str, int], dict[str, int]), + ('tuple', typing.Tuple[str, int], tuple[str, int]), + ('set', typing.Set[str], set[str]), + ('frozenset', typing.FrozenSet[int], frozenset[int]), + ('nested', typing.List[typing.Dict[str, typing.Tuple[int]]], list[dict[str, tuple[int]]]), + ('typevar', typing.List[T], list[T]), + ('nested_typevar', typing.Dict[T, typing.List[U]], dict[T, list[U]]) + + ] + U = typing.TypeVar('U') + + for description, typing_type, expected_builtin_type in test_cases: + converted_type = convert_to_typing_type(convert_to_beam_type(typing_type)) + self.assertEqual(converted_type, expected_builtin_type, description) + + converted_beam_type = convert_to_beam_type(typing_type) + self.assertEqual(convert_to_typing_type(converted_beam_type), typing_type) + + builtin_type = convert_collections_from_typing(typing_type) + self.assertEqual(builtin_type, expected_builtin_type, description) + + + + if __name__ == '__main__': unittest.main() From cee7c4df63888466ca0c91aa1f413c8c00bd5cad Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Thu, 19 Dec 2024 15:34:39 -0500 Subject: [PATCH 2/8] Flip paradigm for convert_to_beam_type to be primative and collections-centric --- .../typehints/native_type_compatibility.py | 125 +++++++++++------- .../native_type_compatibility_test.py | 34 ++--- 2 files changed, 90 insertions(+), 69 deletions(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index f2b6721f8d76..6b4a228ad075 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -20,6 +20,7 @@ # pytype: skip-file import collections +import collections.abc import logging import sys import types @@ -49,7 +50,18 @@ frozenset: typing.FrozenSet, } +_BUILTINS = [ + dict, + list, + tuple, + set, + frozenset, +] + _CONVERTED_COLLECTIONS = [ + collections.abc.Iterable, + collections.abc.Iterator, + collections.abc.Generator, collections.abc.Set, collections.abc.MutableSet, collections.abc.Collection, @@ -103,6 +115,17 @@ def _match_issubclass(match_against): return lambda user_type: _safe_issubclass(user_type, match_against) +def _is_primative(user_type, primative): + # catch bare primatives + if user_type is primative: + return True + return getattr(user_type, '__origin__', None) is primative + + +def _match_is_primative(match_against): + return lambda user_type: _is_primative(user_type, match_against) + + def _match_is_exactly_mapping(user_type): # Avoid unintentionally catching all subtypes (e.g. strings and mappings). expected_origin = collections.abc.Mapping @@ -110,7 +133,7 @@ def _match_is_exactly_mapping(user_type): def _match_is_exactly_iterable(user_type): - if user_type is typing.Iterable: + if user_type is typing.Iterable or user_type is collections.abc.Iterable: return True # Avoid unintentionally catching all subtypes (e.g. strings and mappings). expected_origin = collections.abc.Iterable @@ -156,11 +179,13 @@ def _match_is_union(user_type): return False -def match_is_set(user_type): - if _safe_issubclass(user_type, typing.Set): +def _match_is_set(user_type): + if _safe_issubclass(user_type, typing.Set) or _is_primative(user_type, set): return True elif getattr(user_type, '__origin__', None) is not None: - return _safe_issubclass(user_type.__origin__, collections.abc.Set) + return _safe_issubclass( + user_type.__origin__, collections.abc.Set) or _safe_issubclass( + user_type.__origin__, collections.abc.MutableSet) else: return False @@ -201,6 +226,36 @@ def convert_builtin_to_typing(typ): return typ +def convert_typing_to_builtin(typ): + """Converts a given typing collections type to its builtin counterpart. + + Args: + typ: A typing type (e.g., typing.List[int]). + + Returns: + type: The corresponding builtin type (e.g., list). + """ + origin = getattr(typ, '__origin__', None) + args = getattr(typ, '__args__', None) + # Typing types return the primative type as the origin from 3.9 on + if origin not in _BUILTINS: + return typ + # Early return for bare types + if not args: + return origin + if origin is list: + return list[convert_typing_to_builtin(args[0])] + elif origin is dict: + return dict[convert_typing_to_builtin(args[0]), + convert_typing_to_builtin(args[1])] + elif origin is tuple: + return tuple[tuple(convert_typing_to_builtin(args))] + elif origin is set: + return set[convert_typing_to_builtin(args)] + elif origin is frozenset: + return frozenset[convert_typing_to_builtin(args)] + + def convert_collections_to_typing(typ): """Converts a given collections.abc type to a typing object. @@ -220,6 +275,12 @@ def convert_collections_to_typing(typ): return typ +def is_builtin(typ): + if typ in _BUILTINS: + return True + return getattr(typ, '__origin__', None) in _BUILTINS + + # During type inference of WindowedValue, we need to pass in the inner value # type. This cannot be achieved immediately with WindowedValue class because it # is not parameterized. Changing it to a generic class (e.g. WindowedValue[T]) @@ -254,11 +315,8 @@ def convert_to_beam_type(typ): sys.version_info.minor >= 10) and (isinstance(typ, types.UnionType)): typ = typing.Union[typ] - if isinstance(typ, types.GenericAlias): - typ = convert_builtin_to_typing(typ) - - if getattr(typ, '__module__', None) == 'collections.abc': - typ = convert_collections_to_typing(typ) + if getattr(typ, '__module__', None) == 'typing': + typ = convert_typing_to_builtin(typ) typ_module = getattr(typ, '__module__', None) if isinstance(typ, typing.TypeVar): @@ -289,8 +347,10 @@ def convert_to_beam_type(typ): # to the correct type constraint in Beam # This is needed to fix https://github.com/apache/beam/issues/33356 pass - elif (typ_module != 'typing') and (typ_module != 'collections.abc'): - # Only translate types from the typing and collections.abc modules. + + elif (typ_module != 'typing') and (typ_module != + 'collections.abc') and not is_builtin(typ): + # Only translate primatives and types from the typing and collections.abc modules. return typ if (typ_module == 'collections.abc' and typ.__origin__ not in _CONVERTED_COLLECTIONS): @@ -307,39 +367,34 @@ def convert_to_beam_type(typ): _TypeMapEntry(match=is_forward_ref, arity=0, beam_type=typehints.Any), _TypeMapEntry(match=is_any, arity=0, beam_type=typehints.Any), _TypeMapEntry( - match=_match_issubclass(typing.Dict), - arity=2, - beam_type=typehints.Dict), + match=_match_is_primative(dict), arity=2, beam_type=typehints.Dict), _TypeMapEntry( match=_match_is_exactly_iterable, arity=1, beam_type=typehints.Iterable), _TypeMapEntry( - match=_match_issubclass(typing.List), - arity=1, - beam_type=typehints.List), + match=_match_is_primative(list), arity=1, beam_type=typehints.List), # FrozenSets are a specific instance of a set, so we check this first. _TypeMapEntry( - match=_match_issubclass(typing.FrozenSet), + match=_match_is_primative(frozenset), arity=1, beam_type=typehints.FrozenSet), - _TypeMapEntry(match=match_is_set, arity=1, beam_type=typehints.Set), + _TypeMapEntry(match=_match_is_set, arity=1, beam_type=typehints.Set), # NamedTuple is a subclass of Tuple, but it needs special handling. # We just convert it to Any for now. # This MUST appear before the entry for the normal Tuple. _TypeMapEntry( match=match_is_named_tuple, arity=0, beam_type=typehints.Any), _TypeMapEntry( - match=_match_issubclass(typing.Tuple), - arity=-1, + match=_match_is_primative(tuple), arity=-1, beam_type=typehints.Tuple), _TypeMapEntry(match=_match_is_union, arity=-1, beam_type=typehints.Union), _TypeMapEntry( - match=_match_issubclass(typing.Generator), + match=_match_issubclass(collections.abc.Generator), arity=3, beam_type=typehints.Generator), _TypeMapEntry( - match=_match_issubclass(typing.Iterator), + match=_match_issubclass(collections.abc.Iterator), arity=1, beam_type=typehints.Iterator), _TypeMapEntry( @@ -472,30 +527,6 @@ def convert_to_typing_type(typ): raise ValueError('Failed to convert Beam type: %s' % typ) -def convert_collections_from_typing(typ): - """Converts a given typing collections type to its builtin counterpart. - - Args: - typ: A typing type (e.g., typing.List[int]). - - Returns: - type: The corresponding builtin type (e.g., list). - """ - origin = getattr(typ, '__origin__', None) - if origin is typing.List: - return list[convert_to_typing_type(typ.__args__[0])] - elif origin is typing.Dict: - return dict[convert_to_typing_type(typ.__args__[0]), convert_to_typing_type(typ.__args__[1])] - elif origin is typing.Tuple: - return tuple[tuple(convert_to_typing_types(typ.__args__))] - elif origin is typing.Set: - return set[convert_to_typing_type(typ.__args__[0])] - elif origin is typing.FrozenSet: - return frozenset[convert_to_typing_type(typ.__args__[0])] - else: - return typ - - def convert_to_typing_types(args): """Convert the given list or dictionary of args to typing types. diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py index 02cfe3287c3e..1b5f6051ce0b 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py @@ -30,7 +30,7 @@ from apache_beam.typehints.native_type_compatibility import convert_to_beam_types from apache_beam.typehints.native_type_compatibility import convert_to_typing_type from apache_beam.typehints.native_type_compatibility import convert_to_typing_types -from apache_beam.typehints.native_type_compatibility import convert_collections_from_typing, is_any +from apache_beam.typehints.native_type_compatibility import convert_typing_to_builtin, is_any _TestNamedTuple = typing.NamedTuple( '_TestNamedTuple', [('age', int), ('name', bytes)]) @@ -141,7 +141,7 @@ def test_convert_to_beam_type_with_builtin_types(self): ( 'builtin nested tuple', tuple[str, list], - typehints.Tuple[str, typehints.List[typehints.Any]], + typehints.Tuple[str, typehints.List[typehints.TypeVariable('T')]], ) ] @@ -160,7 +160,7 @@ def test_convert_to_beam_type_with_collections_types(self): typehints.Iterable[int]), ( 'collection generator', - collections.abc.Generator[int], + collections.abc.Generator[int, None, None], typehints.Generator[int]), ( 'collection iterator', @@ -178,9 +178,8 @@ def test_convert_to_beam_type_with_collections_types(self): 'mapping not caught', collections.abc.Mapping[str, int], collections.abc.Mapping[str, int]), - ('set', collections.abc.Set[str], typehints.Set[str]), + ('set', collections.abc.Set[int], typehints.Set[int]), ('mutable set', collections.abc.MutableSet[int], typehints.Set[int]), - ('enum set', collections.abc.Set[_TestEnum], typehints.Set[_TestEnum]), ( 'enum mutable set', collections.abc.MutableSet[_TestEnum], @@ -338,33 +337,24 @@ def test_is_any(self): for expected, typ in test_cases: self.assertEqual(expected, is_any(typ), msg='%s' % typ) - def test_convert_collections_from_typing(self): + def test_convert_typing_to_builtin(self): test_cases = [ - ('list', typing.List[int], list[int]), - ('dict', typing.Dict[str, int], dict[str, int]), + ('list', typing.List[int], + list[int]), ('dict', typing.Dict[str, int], dict[str, int]), ('tuple', typing.Tuple[str, int], tuple[str, int]), ('set', typing.Set[str], set[str]), ('frozenset', typing.FrozenSet[int], frozenset[int]), - ('nested', typing.List[typing.Dict[str, typing.Tuple[int]]], list[dict[str, tuple[int]]]), - ('typevar', typing.List[T], list[T]), + ( + 'nested', + typing.List[typing.Dict[str, typing.Tuple[int]]], + list[dict[str, tuple[int]]]), ('typevar', typing.List[T], list[T]), ('nested_typevar', typing.Dict[T, typing.List[U]], dict[T, list[U]]) - ] - U = typing.TypeVar('U') for description, typing_type, expected_builtin_type in test_cases: - converted_type = convert_to_typing_type(convert_to_beam_type(typing_type)) - self.assertEqual(converted_type, expected_builtin_type, description) - - converted_beam_type = convert_to_beam_type(typing_type) - self.assertEqual(convert_to_typing_type(converted_beam_type), typing_type) - - builtin_type = convert_collections_from_typing(typing_type) + builtin_type = convert_typing_to_builtin(typing_type) self.assertEqual(builtin_type, expected_builtin_type, description) - - - if __name__ == '__main__': unittest.main() From aa7b2645f5cc6b6984c86fed3b67e27241a6f546 Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Mon, 6 Jan 2025 10:28:07 -0500 Subject: [PATCH 3/8] update comment --- sdks/python/apache_beam/typehints/native_type_compatibility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index 6b4a228ad075..ac61225a3989 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -350,7 +350,7 @@ def convert_to_beam_type(typ): elif (typ_module != 'typing') and (typ_module != 'collections.abc') and not is_builtin(typ): - # Only translate primatives and types from the typing and collections.abc modules. + # Only translate primatives and types from collections.abc and typing. return typ if (typ_module == 'collections.abc' and typ.__origin__ not in _CONVERTED_COLLECTIONS): From 32fbbede72e8da20b2ba06eef1f74733f6086d45 Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Mon, 6 Jan 2025 10:35:04 -0500 Subject: [PATCH 4/8] fix clobbered import from merge --- .../python/apache_beam/typehints/native_type_compatibility.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index b482a22ebd59..00172a9d453e 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -25,9 +25,13 @@ import sys import types import typing +from typing import Generic +from typing import TypeVar from apache_beam.typehints import typehints +T = TypeVar('T') + _LOGGER = logging.getLogger(__name__) # Describes an entry in the type map in convert_to_beam_type. From 55475b8adee64b97e2804e9c82830d42b7fdf55e Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Mon, 6 Jan 2025 10:48:01 -0500 Subject: [PATCH 5/8] formatting --- .../python/apache_beam/typehints/native_type_compatibility.py | 4 ++-- 1 file changed, 2 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 00172a9d453e..5137a83716b6 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -292,7 +292,7 @@ class TypedWindowedValue(Generic[T]): def __init__(self, *args, **kwargs): raise NotImplementedError("This class is solely for type inference") - + def convert_to_beam_type(typ): """Convert a given typing type to a Beam type. @@ -347,7 +347,7 @@ def convert_to_beam_type(typ): # to the correct type constraint in Beam # This is needed to fix https://github.com/apache/beam/issues/33356 pass - + elif (typ_module != 'typing') and (typ_module != 'collections.abc') and not is_builtin(typ): # Only translate primatives and types from collections.abc and typing. From 57414792dfda6cc526442d5a3919d2ade48783da Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Mon, 6 Jan 2025 11:15:27 -0500 Subject: [PATCH 6/8] fix imports --- .../apache_beam/typehints/native_type_compatibility_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py index 1b5f6051ce0b..15b5da99fb0c 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py @@ -30,7 +30,8 @@ from apache_beam.typehints.native_type_compatibility import convert_to_beam_types from apache_beam.typehints.native_type_compatibility import convert_to_typing_type from apache_beam.typehints.native_type_compatibility import convert_to_typing_types -from apache_beam.typehints.native_type_compatibility import convert_typing_to_builtin, is_any +from apache_beam.typehints.native_type_compatibility import convert_typing_to_builtin +from apache_beam.typehints.native_type_compatibility import is_any _TestNamedTuple = typing.NamedTuple( '_TestNamedTuple', [('age', int), ('name', bytes)]) From b78944db196b02774d245959cd10ddbba630c3d8 Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Tue, 7 Jan 2025 11:08:04 -0500 Subject: [PATCH 7/8] address comments --- .../typehints/native_type_compatibility.py | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index 5137a83716b6..3fe30bc86505 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -115,15 +115,15 @@ def _match_issubclass(match_against): return lambda user_type: _safe_issubclass(user_type, match_against) -def _is_primative(user_type, primative): - # catch bare primatives - if user_type is primative: +def _is_primitive(user_type, primitive): + # catch bare primitives + if user_type is primitive: return True - return getattr(user_type, '__origin__', None) is primative + return getattr(user_type, '__origin__', None) is primitive -def _match_is_primative(match_against): - return lambda user_type: _is_primative(user_type, match_against) +def _match_is_primitive(match_against): + return lambda user_type: _is_primitive(user_type, match_against) def _match_is_exactly_mapping(user_type): @@ -180,7 +180,7 @@ def _match_is_union(user_type): def _match_is_set(user_type): - if _safe_issubclass(user_type, typing.Set) or _is_primative(user_type, set): + if _safe_issubclass(user_type, typing.Set) or _is_primitive(user_type, set): return True elif getattr(user_type, '__origin__', None) is not None: return _safe_issubclass( @@ -233,11 +233,11 @@ def convert_typing_to_builtin(typ): typ: A typing type (e.g., typing.List[int]). Returns: - type: The corresponding builtin type (e.g., list). + type: The corresponding builtin type (e.g., list[int]). """ origin = getattr(typ, '__origin__', None) args = getattr(typ, '__args__', None) - # Typing types return the primative type as the origin from 3.9 on + # Typing types return the primitive type as the origin from 3.9 on if origin not in _BUILTINS: return typ # Early return for bare types @@ -281,18 +281,6 @@ def is_builtin(typ): return getattr(typ, '__origin__', None) in _BUILTINS -# During type inference of WindowedValue, we need to pass in the inner value -# type. This cannot be achieved immediately with WindowedValue class because it -# is not parameterized. Changing it to a generic class (e.g. WindowedValue[T]) -# could work in theory. However, the class is cythonized and it seems that -# cython does not handle generic classes well. -# The workaround here is to create a separate class solely for the type -# inference purpose. This class should never be used for creating instances. -class TypedWindowedValue(Generic[T]): - def __init__(self, *args, **kwargs): - raise NotImplementedError("This class is solely for type inference") - - def convert_to_beam_type(typ): """Convert a given typing type to a Beam type. @@ -350,7 +338,7 @@ def convert_to_beam_type(typ): elif (typ_module != 'typing') and (typ_module != 'collections.abc') and not is_builtin(typ): - # Only translate primatives and types from collections.abc and typing. + # Only translate primitives and types from collections.abc and typing. return typ if (typ_module == 'collections.abc' and typ.__origin__ not in _CONVERTED_COLLECTIONS): @@ -367,16 +355,16 @@ def convert_to_beam_type(typ): _TypeMapEntry(match=is_forward_ref, arity=0, beam_type=typehints.Any), _TypeMapEntry(match=is_any, arity=0, beam_type=typehints.Any), _TypeMapEntry( - match=_match_is_primative(dict), arity=2, beam_type=typehints.Dict), + match=_match_is_primitive(dict), arity=2, beam_type=typehints.Dict), _TypeMapEntry( match=_match_is_exactly_iterable, arity=1, beam_type=typehints.Iterable), _TypeMapEntry( - match=_match_is_primative(list), arity=1, beam_type=typehints.List), + match=_match_is_primitive(list), arity=1, beam_type=typehints.List), # FrozenSets are a specific instance of a set, so we check this first. _TypeMapEntry( - match=_match_is_primative(frozenset), + match=_match_is_primitive(frozenset), arity=1, beam_type=typehints.FrozenSet), _TypeMapEntry(match=_match_is_set, arity=1, beam_type=typehints.Set), @@ -386,7 +374,7 @@ def convert_to_beam_type(typ): _TypeMapEntry( match=match_is_named_tuple, arity=0, beam_type=typehints.Any), _TypeMapEntry( - match=_match_is_primative(tuple), arity=-1, + match=_match_is_primitive(tuple), arity=-1, beam_type=typehints.Tuple), _TypeMapEntry(match=_match_is_union, arity=-1, beam_type=typehints.Union), _TypeMapEntry( From 2984d9ccebfcc72fe0a0bb5258109a214e9d972b Mon Sep 17 00:00:00 2001 From: Jack McCluskey Date: Tue, 7 Jan 2025 11:12:30 -0500 Subject: [PATCH 8/8] remove extra import artifacts from merge --- .../python/apache_beam/typehints/native_type_compatibility.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index 3fe30bc86505..3f57a573b505 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -25,13 +25,9 @@ import sys import types import typing -from typing import Generic -from typing import TypeVar from apache_beam.typehints import typehints -T = TypeVar('T') - _LOGGER = logging.getLogger(__name__) # Describes an entry in the type map in convert_to_beam_type.