This is an automated email from the ASF dual-hosted git repository.

jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 63b8dd17d6c Remove unnecessary branches on Python version in typehint 
code (#33258)
63b8dd17d6c is described below

commit 63b8dd17d6cba28cbcc415981bab423767ad7c60
Author: Jack McCluskey <[email protected]>
AuthorDate: Tue Dec 3 09:57:06 2024 -0500

    Remove unnecessary branches on Python version in typehint code (#33258)
    
    * Remove unneccessary branches on Python version in typehint code
    
    * remove unused imports
---
 sdks/python/apache_beam/typehints/decorators.py    |   4 -
 .../apache_beam/typehints/decorators_test.py       |  10 +-
 .../typehints/native_type_compatibility.py         |  15 +-
 .../typehints/native_type_compatibility_test.py    | 195 ++++++++++-----------
 sdks/python/apache_beam/typehints/opcodes.py       |  12 +-
 .../apache_beam/typehints/typed_pipeline_test.py   |   8 +-
 sdks/python/apache_beam/typehints/typehints.py     |   8 +-
 .../python/apache_beam/typehints/typehints_test.py | 140 +++++----------
 8 files changed, 149 insertions(+), 243 deletions(-)

diff --git a/sdks/python/apache_beam/typehints/decorators.py 
b/sdks/python/apache_beam/typehints/decorators.py
index 9c0cc2b8af4..7050df7016e 100644
--- a/sdks/python/apache_beam/typehints/decorators.py
+++ b/sdks/python/apache_beam/typehints/decorators.py
@@ -82,7 +82,6 @@ defined, or before importing a module containing type-hinted 
functions.
 import inspect
 import itertools
 import logging
-import sys
 import traceback
 import types
 from typing import Any
@@ -686,9 +685,6 @@ def get_type_hints(fn: Any) -> IOTypeHints:
       # Can't add arbitrary attributes to this object,
       # but might have some restrictions anyways...
       hints = IOTypeHints.empty()
-      # Python 3.7 introduces annotations for _MethodDescriptorTypes.
-      if isinstance(fn, _MethodDescriptorType) and sys.version_info < (3, 7):
-        hints = hints.with_input_types(fn.__objclass__)  # type: ignore
       return hints
   return fn._type_hints
   # pylint: enable=protected-access
diff --git a/sdks/python/apache_beam/typehints/decorators_test.py 
b/sdks/python/apache_beam/typehints/decorators_test.py
index 71edc75f31a..dd110ced5bb 100644
--- a/sdks/python/apache_beam/typehints/decorators_test.py
+++ b/sdks/python/apache_beam/typehints/decorators_test.py
@@ -20,7 +20,6 @@
 # pytype: skip-file
 
 import functools
-import sys
 import typing
 import unittest
 
@@ -70,14 +69,7 @@ class IOTypeHintsTest(unittest.TestCase):
   def test_from_callable_method_descriptor(self):
     # from_callable() injects an annotation in this special type of builtin.
     th = decorators.IOTypeHints.from_callable(str.strip)
-    if sys.version_info >= (3, 7):
-      self.assertEqual(th.input_types, ((str, Any), {}))
-    else:
-      self.assertEqual(
-          th.input_types,
-          ((str, decorators._ANY_VAR_POSITIONAL), {
-              '__unknown__keywords': decorators._ANY_VAR_KEYWORD
-          }))
+    self.assertEqual(th.input_types, ((str, Any), {}))
     self.assertEqual(th.output_types, ((Any, ), {}))
 
   def test_strip_iterable_not_simple_output_noop(self):
diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py 
b/sdks/python/apache_beam/typehints/native_type_compatibility.py
index 621adc44507..6f704b37a96 100644
--- a/sdks/python/apache_beam/typehints/native_type_compatibility.py
+++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py
@@ -101,10 +101,7 @@ def _match_issubclass(match_against):
 
 def _match_is_exactly_mapping(user_type):
   # Avoid unintentionally catching all subtypes (e.g. strings and mappings).
-  if sys.version_info < (3, 7):
-    expected_origin = typing.Mapping
-  else:
-    expected_origin = collections.abc.Mapping
+  expected_origin = collections.abc.Mapping
   return getattr(user_type, '__origin__', None) is expected_origin
 
 
@@ -112,10 +109,7 @@ def _match_is_exactly_iterable(user_type):
   if user_type is typing.Iterable:
     return True
   # Avoid unintentionally catching all subtypes (e.g. strings and mappings).
-  if sys.version_info < (3, 7):
-    expected_origin = typing.Iterable
-  else:
-    expected_origin = collections.abc.Iterable
+  expected_origin = collections.abc.Iterable
   return getattr(user_type, '__origin__', None) is expected_origin
 
 
@@ -244,11 +238,10 @@ def convert_to_beam_type(typ):
       sys.version_info.minor >= 10) and (isinstance(typ, types.UnionType)):
     typ = typing.Union[typ]
 
-  if sys.version_info >= (3, 9) and isinstance(typ, types.GenericAlias):
+  if isinstance(typ, types.GenericAlias):
     typ = convert_builtin_to_typing(typ)
 
-  if sys.version_info >= (3, 9) and getattr(typ, '__module__',
-                                            None) == 'collections.abc':
+  if getattr(typ, '__module__', None) == 'collections.abc':
     typ = convert_collections_to_typing(typ)
 
   typ_module = getattr(typ, '__module__', None)
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 2e6db6a7733..ae8e1a0b290 100644
--- a/sdks/python/apache_beam/typehints/native_type_compatibility_test.py
+++ b/sdks/python/apache_beam/typehints/native_type_compatibility_test.py
@@ -21,7 +21,6 @@
 
 import collections.abc
 import enum
-import sys
 import typing
 import unittest
 
@@ -128,105 +127,98 @@ class NativeTypeCompatibilityTest(unittest.TestCase):
       self.assertEqual(converted_typing_type, typing_type, description)
 
   def test_convert_to_beam_type_with_builtin_types(self):
-    if sys.version_info >= (3, 9):
-      test_cases = [
-          ('builtin dict', dict[str, int], typehints.Dict[str, int]),
-          ('builtin list', list[str], typehints.List[str]),
-          ('builtin tuple', tuple[str],
-           typehints.Tuple[str]), ('builtin set', set[str], 
typehints.Set[str]),
-          ('builtin frozenset', frozenset[int], typehints.FrozenSet[int]),
-          (
-              'nested builtin',
-              dict[str, list[tuple[float]]],
-              typehints.Dict[str, typehints.List[typehints.Tuple[float]]]),
-          (
-              'builtin nested tuple',
-              tuple[str, list],
-              typehints.Tuple[str, typehints.List[typehints.Any]],
-          )
-      ]
-
-      for test_case in test_cases:
-        description = test_case[0]
-        builtins_type = test_case[1]
-        expected_beam_type = test_case[2]
-        converted_beam_type = convert_to_beam_type(builtins_type)
-        self.assertEqual(converted_beam_type, expected_beam_type, description)
+    test_cases = [
+        ('builtin dict', dict[str, int], typehints.Dict[str, int]),
+        ('builtin list', list[str], typehints.List[str]),
+        ('builtin tuple', tuple[str],
+         typehints.Tuple[str]), ('builtin set', set[str], typehints.Set[str]),
+        ('builtin frozenset', frozenset[int], typehints.FrozenSet[int]),
+        (
+            'nested builtin',
+            dict[str, list[tuple[float]]],
+            typehints.Dict[str, typehints.List[typehints.Tuple[float]]]),
+        (
+            'builtin nested tuple',
+            tuple[str, list],
+            typehints.Tuple[str, typehints.List[typehints.Any]],
+        )
+    ]
+
+    for test_case in test_cases:
+      description = test_case[0]
+      builtins_type = test_case[1]
+      expected_beam_type = test_case[2]
+      converted_beam_type = convert_to_beam_type(builtins_type)
+      self.assertEqual(converted_beam_type, expected_beam_type, description)
 
   def test_convert_to_beam_type_with_collections_types(self):
-    if sys.version_info >= (3, 9):
-      test_cases = [
-          (
-              'collection iterable',
-              collections.abc.Iterable[int],
-              typehints.Iterable[int]),
-          (
-              'collection generator',
-              collections.abc.Generator[int],
-              typehints.Generator[int]),
-          (
-              'collection iterator',
-              collections.abc.Iterator[int],
-              typehints.Iterator[int]),
-          (
-              'nested iterable',
-              tuple[bytes, collections.abc.Iterable[int]],
-              typehints.Tuple[bytes, typehints.Iterable[int]]),
-          (
-              'iterable over tuple',
-              collections.abc.Iterable[tuple[str, int]],
-              typehints.Iterable[typehints.Tuple[str, int]]),
-          (
-              'mapping not caught',
-              collections.abc.Mapping[str, int],
-              collections.abc.Mapping[str, int]),
-          ('set', collections.abc.Set[str], typehints.Set[str]),
-          ('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],
-              typehints.Set[_TestEnum]),
-          (
-              'collection enum',
-              collections.abc.Collection[_TestEnum],
-              typehints.Collection[_TestEnum]),
-          (
-              'collection of tuples',
-              collections.abc.Collection[tuple[str, int]],
-              typehints.Collection[typehints.Tuple[str, int]]),
-      ]
-
-      for test_case in test_cases:
-        description = test_case[0]
-        builtins_type = test_case[1]
-        expected_beam_type = test_case[2]
-        converted_beam_type = convert_to_beam_type(builtins_type)
-        self.assertEqual(converted_beam_type, expected_beam_type, description)
+    test_cases = [
+        (
+            'collection iterable',
+            collections.abc.Iterable[int],
+            typehints.Iterable[int]),
+        (
+            'collection generator',
+            collections.abc.Generator[int],
+            typehints.Generator[int]),
+        (
+            'collection iterator',
+            collections.abc.Iterator[int],
+            typehints.Iterator[int]),
+        (
+            'nested iterable',
+            tuple[bytes, collections.abc.Iterable[int]],
+            typehints.Tuple[bytes, typehints.Iterable[int]]),
+        (
+            'iterable over tuple',
+            collections.abc.Iterable[tuple[str, int]],
+            typehints.Iterable[typehints.Tuple[str, int]]),
+        (
+            'mapping not caught',
+            collections.abc.Mapping[str, int],
+            collections.abc.Mapping[str, int]),
+        ('set', collections.abc.Set[str], typehints.Set[str]),
+        ('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],
+            typehints.Set[_TestEnum]),
+        (
+            'collection enum',
+            collections.abc.Collection[_TestEnum],
+            typehints.Collection[_TestEnum]),
+        (
+            'collection of tuples',
+            collections.abc.Collection[tuple[str, int]],
+            typehints.Collection[typehints.Tuple[str, int]]),
+    ]
+
+    for test_case in test_cases:
+      description = test_case[0]
+      builtins_type = test_case[1]
+      expected_beam_type = test_case[2]
+      converted_beam_type = convert_to_beam_type(builtins_type)
+      self.assertEqual(converted_beam_type, expected_beam_type, description)
 
   def test_convert_builtin_to_typing(self):
-    if sys.version_info >= (3, 9):
-      test_cases = [
-          ('dict', dict[str, int], typing.Dict[str, int]),
-          ('list', list[str], typing.List[str]),
-          ('tuple', tuple[str], typing.Tuple[str]),
-          ('set', set[str], typing.Set[str]),
-          (
-              'nested',
-              dict[str, list[tuple[float]]],
-              typing.Dict[str, typing.List[typing.Tuple[float]]]),
-      ]
-
-      for test_case in test_cases:
-        description = test_case[0]
-        builtin_type = test_case[1]
-        expected_typing_type = test_case[2]
-        converted_typing_type = convert_builtin_to_typing(builtin_type)
-        self.assertEqual(
-            converted_typing_type, expected_typing_type, description)
+    test_cases = [
+        ('dict', dict[str, int], typing.Dict[str, int]),
+        ('list', list[str], typing.List[str]),
+        ('tuple', tuple[str], typing.Tuple[str]),
+        ('set', set[str], typing.Set[str]),
+        (
+            'nested',
+            dict[str, list[tuple[float]]],
+            typing.Dict[str, typing.List[typing.Tuple[float]]]),
+    ]
+
+    for test_case in test_cases:
+      description = test_case[0]
+      builtin_type = test_case[1]
+      expected_typing_type = test_case[2]
+      converted_typing_type = convert_builtin_to_typing(builtin_type)
+      self.assertEqual(converted_typing_type, expected_typing_type, 
description)
 
   def test_generator_converted_to_iterator(self):
     self.assertEqual(
@@ -293,14 +285,11 @@ class NativeTypeCompatibilityTest(unittest.TestCase):
             typing.Tuple[typing.Iterator],
             typehints.Tuple[typehints.Iterator[typehints.TypeVariable('T_co')]]
         ),
+        (
+            'bare generator',
+            typing.Generator,
+            typehints.Generator[typehints.TypeVariable('T_co')]),
     ]
-    if sys.version_info >= (3, 7):
-      test_cases += [
-          (
-              'bare generator',
-              typing.Generator,
-              typehints.Generator[typehints.TypeVariable('T_co')]),
-      ]
     for test_case in test_cases:
       description = test_case[0]
       typing_type = test_case[1]
diff --git a/sdks/python/apache_beam/typehints/opcodes.py 
b/sdks/python/apache_beam/typehints/opcodes.py
index 62c7a8fadc3..7bea621841f 100644
--- a/sdks/python/apache_beam/typehints/opcodes.py
+++ b/sdks/python/apache_beam/typehints/opcodes.py
@@ -246,14 +246,10 @@ def set_add(state, arg):
 
 
 def map_add(state, arg):
-  if sys.version_info >= (3, 8):
-    # PEP 572 The MAP_ADD expects the value as the first element in the stack
-    # and the key as the second element.
-    new_value_type = Const.unwrap(state.stack.pop())
-    new_key_type = Const.unwrap(state.stack.pop())
-  else:
-    new_key_type = Const.unwrap(state.stack.pop())
-    new_value_type = Const.unwrap(state.stack.pop())
+  # PEP 572 The MAP_ADD expects the value as the first element in the stack
+  # and the key as the second element.
+  new_value_type = Const.unwrap(state.stack.pop())
+  new_key_type = Const.unwrap(state.stack.pop())
   state.stack[-arg] = Dict[Union[state.stack[-arg].key_type, new_key_type],
                            Union[state.stack[-arg].value_type, new_value_type]]
 
diff --git a/sdks/python/apache_beam/typehints/typed_pipeline_test.py 
b/sdks/python/apache_beam/typehints/typed_pipeline_test.py
index 57e7f44f692..44318fa44a8 100644
--- a/sdks/python/apache_beam/typehints/typed_pipeline_test.py
+++ b/sdks/python/apache_beam/typehints/typed_pipeline_test.py
@@ -19,7 +19,6 @@
 
 # pytype: skip-file
 
-import sys
 import typing
 import unittest
 
@@ -874,12 +873,7 @@ class CustomTransformTest(unittest.TestCase):
 class AnnotationsTest(unittest.TestCase):
   def test_pardo_wrapper_builtin_method(self):
     th = beam.ParDo(str.strip).get_type_hints()
-    if sys.version_info < (3, 7):
-      self.assertEqual(th.input_types, ((str, ), {}))
-    else:
-      # Python 3.7+ has annotations for CPython builtins
-      # (_MethodDescriptorType).
-      self.assertEqual(th.input_types, ((str, typehints.Any), {}))
+    self.assertEqual(th.input_types, ((str, typehints.Any), {}))
     self.assertEqual(th.output_types, ((typehints.Any, ), {}))
 
   def test_pardo_wrapper_builtin_type(self):
diff --git a/sdks/python/apache_beam/typehints/typehints.py 
b/sdks/python/apache_beam/typehints/typehints.py
index 912cb78dc09..0e18e887c2a 100644
--- a/sdks/python/apache_beam/typehints/typehints.py
+++ b/sdks/python/apache_beam/typehints/typehints.py
@@ -391,12 +391,6 @@ def validate_composite_type_param(type_param, 
error_msg_prefix):
   if sys.version_info.major == 3 and sys.version_info.minor >= 10:
     if isinstance(type_param, types.UnionType):
       is_not_type_constraint = False
-  # Pre-Python 3.9 compositve type-hinting with built-in types was not
-  # supported, the typing module equivalents should be used instead.
-  if sys.version_info.major == 3 and sys.version_info.minor < 9:
-    is_not_type_constraint = is_not_type_constraint or (
-        isinstance(type_param, type) and
-        type_param in DISALLOWED_PRIMITIVE_TYPES)
 
   if is_not_type_constraint:
     raise TypeError(
@@ -1266,7 +1260,7 @@ def normalize(x, none_as_type=False):
   # Avoid circular imports
   from apache_beam.typehints import native_type_compatibility
 
-  if sys.version_info >= (3, 9) and isinstance(x, types.GenericAlias):
+  if isinstance(x, types.GenericAlias):
     x = native_type_compatibility.convert_builtin_to_typing(x)
 
   if none_as_type and x is None:
diff --git a/sdks/python/apache_beam/typehints/typehints_test.py 
b/sdks/python/apache_beam/typehints/typehints_test.py
index 843c1498cac..6611dcecab0 100644
--- a/sdks/python/apache_beam/typehints/typehints_test.py
+++ b/sdks/python/apache_beam/typehints/typehints_test.py
@@ -388,15 +388,10 @@ class TupleHintTestCase(TypeHintTestCase):
       typehints.Tuple[5, [1, 3]]
     self.assertTrue(e.exception.args[0].startswith(expected_error_prefix))
 
-    if sys.version_info < (3, 9):
-      with self.assertRaises(TypeError) as e:
-        typehints.Tuple[list, dict]
-      self.assertTrue(e.exception.args[0].startswith(expected_error_prefix))
-    else:
-      try:
-        typehints.Tuple[list, dict]
-      except TypeError:
-        self.fail("built-in composite raised TypeError unexpectedly")
+    try:
+      typehints.Tuple[list, dict]
+    except TypeError:
+      self.fail("built-in composite raised TypeError unexpectedly")
 
   def test_compatibility_arbitrary_length(self):
     self.assertNotCompatible(
@@ -548,15 +543,13 @@ class TupleHintTestCase(TypeHintTestCase):
         e.exception.args[0])
 
   def test_normalize_with_builtin_tuple(self):
-    if sys.version_info >= (3, 9):
-      expected_beam_type = typehints.Tuple[int, int]
-      converted_beam_type = typehints.normalize(tuple[int, int], False)
-      self.assertEqual(converted_beam_type, expected_beam_type)
+    expected_beam_type = typehints.Tuple[int, int]
+    converted_beam_type = typehints.normalize(tuple[int, int], False)
+    self.assertEqual(converted_beam_type, expected_beam_type)
 
   def test_builtin_and_type_compatibility(self):
-    if sys.version_info >= (3, 9):
-      self.assertCompatible(tuple, typing.Tuple)
-      self.assertCompatible(tuple[int, int], typing.Tuple[int, int])
+    self.assertCompatible(tuple, typing.Tuple)
+    self.assertCompatible(tuple[int, int], typing.Tuple[int, int])
 
 
 class ListHintTestCase(TypeHintTestCase):
@@ -618,22 +611,19 @@ class ListHintTestCase(TypeHintTestCase):
         e.exception.args[0])
 
   def test_normalize_with_builtin_list(self):
-    if sys.version_info >= (3, 9):
-      expected_beam_type = typehints.List[int]
-      converted_beam_type = typehints.normalize(list[int], False)
-      self.assertEqual(converted_beam_type, expected_beam_type)
+    expected_beam_type = typehints.List[int]
+    converted_beam_type = typehints.normalize(list[int], False)
+    self.assertEqual(converted_beam_type, expected_beam_type)
 
   def test_builtin_and_type_compatibility(self):
-    if sys.version_info >= (3, 9):
-      self.assertCompatible(list, typing.List)
-      self.assertCompatible(list[int], typing.List[int])
+    self.assertCompatible(list, typing.List)
+    self.assertCompatible(list[int], typing.List[int])
 
   def test_is_typing_generic(self):
     self.assertTrue(typehints.is_typing_generic(typing.List[str]))
 
   def test_builtin_is_typing_generic(self):
-    if sys.version_info >= (3, 9):
-      self.assertTrue(typehints.is_typing_generic(list[str]))
+    self.assertTrue(typehints.is_typing_generic(list[str]))
 
 
 class KVHintTestCase(TypeHintTestCase):
@@ -687,14 +677,10 @@ class DictHintTestCase(TypeHintTestCase):
         e.exception.args[0])
 
   def test_key_type_must_be_valid_composite_param(self):
-    if sys.version_info < (3, 9):
-      with self.assertRaises(TypeError):
-        typehints.Dict[list, int]
-    else:
-      try:
-        typehints.Tuple[list, int]
-      except TypeError:
-        self.fail("built-in composite raised TypeError unexpectedly")
+    try:
+      typehints.Tuple[list, int]
+    except TypeError:
+      self.fail("built-in composite raised TypeError unexpectedly")
 
   def test_value_type_must_be_valid_composite_param(self):
     with self.assertRaises(TypeError):
@@ -777,35 +763,24 @@ class DictHintTestCase(TypeHintTestCase):
                      hint.match_type_variables(typehints.Dict[int, str]))
 
   def test_normalize_with_builtin_dict(self):
-    if sys.version_info >= (3, 9):
-      expected_beam_type = typehints.Dict[str, int]
-      converted_beam_type = typehints.normalize(dict[str, int], False)
-      self.assertEqual(converted_beam_type, expected_beam_type)
+    expected_beam_type = typehints.Dict[str, int]
+    converted_beam_type = typehints.normalize(dict[str, int], False)
+    self.assertEqual(converted_beam_type, expected_beam_type)
 
   def test_builtin_and_type_compatibility(self):
-    if sys.version_info >= (3, 9):
-      self.assertCompatible(dict, typing.Dict)
-      self.assertCompatible(dict[str, int], typing.Dict[str, int])
-      self.assertCompatible(
-          dict[str, list[int]], typing.Dict[str, typing.List[int]])
+    self.assertCompatible(dict, typing.Dict)
+    self.assertCompatible(dict[str, int], typing.Dict[str, int])
+    self.assertCompatible(
+        dict[str, list[int]], typing.Dict[str, typing.List[int]])
 
 
 class BaseSetHintTest:
   class CommonTests(TypeHintTestCase):
     def test_getitem_invalid_composite_type_param(self):
-      if sys.version_info < (3, 9):
-        with self.assertRaises(TypeError) as e:
-          self.beam_type[list]
-        self.assertEqual(
-            "Parameter to a {} hint must be a non-sequence, a "
-            "type, or a TypeConstraint. {} is an instance of "
-            "type.".format(self.string_type, list),
-            e.exception.args[0])
-      else:
-        try:
-          self.beam_type[list]
-        except TypeError:
-          self.fail("built-in composite raised TypeError unexpectedly")
+      try:
+        self.beam_type[list]
+      except TypeError:
+        self.fail("built-in composite raised TypeError unexpectedly")
 
     def test_non_typing_generic(self):
       testCase = DummyTestClass1()
@@ -855,16 +830,14 @@ class SetHintTestCase(BaseSetHintTest.CommonTests):
   string_type = 'Set'
 
   def test_builtin_compatibility(self):
-    if sys.version_info >= (3, 9):
-      self.assertCompatible(set[int], collections.abc.Set[int])
-      self.assertCompatible(set[int], collections.abc.MutableSet[int])
+    self.assertCompatible(set[int], collections.abc.Set[int])
+    self.assertCompatible(set[int], collections.abc.MutableSet[int])
 
   def test_collections_compatibility(self):
-    if sys.version_info >= (3, 9):
-      self.assertCompatible(
-          collections.abc.Set[int], collections.abc.MutableSet[int])
-      self.assertCompatible(
-          collections.abc.MutableSet[int], collections.abc.Set[int])
+    self.assertCompatible(
+        collections.abc.Set[int], collections.abc.MutableSet[int])
+    self.assertCompatible(
+        collections.abc.MutableSet[int], collections.abc.Set[int])
 
 
 class FrozenSetHintTestCase(BaseSetHintTest.CommonTests):
@@ -1416,37 +1389,16 @@ class DecoratorHelpers(TypeHintTestCase):
                          func, *[Any, Any, Tuple[str, ...], int]))
 
   def test_getcallargs_forhints_builtins(self):
-    if sys.version_info < (3, 7):
-      # Signatures for builtins are not supported in 3.5 and 3.6.
-      self.assertEqual({
-          '_': str,
-          '__unknown__varargs': Tuple[Any, ...],
-          '__unknown__keywords': typehints.Dict[Any, Any]
-      },
-                       getcallargs_forhints(str.upper, str))
-      self.assertEqual({
-          '_': str,
-          '__unknown__varargs': Tuple[str, ...],
-          '__unknown__keywords': typehints.Dict[Any, Any]
-      },
-                       getcallargs_forhints(str.strip, str, str))
-      self.assertEqual({
-          '_': str,
-          '__unknown__varargs': Tuple[typehints.List[int], ...],
-          '__unknown__keywords': typehints.Dict[Any, Any]
-      },
-                       getcallargs_forhints(str.join, str, 
typehints.List[int]))
-    else:
-      self.assertEqual({'self': str}, getcallargs_forhints(str.upper, str))
-      # str.strip has an optional second argument.
-      self.assertEqual({
-          'self': str, 'chars': Any
-      },
-                       getcallargs_forhints(str.strip, str))
-      self.assertEqual({
-          'self': str, 'iterable': typehints.List[int]
-      },
-                       getcallargs_forhints(str.join, str, 
typehints.List[int]))
+    self.assertEqual({'self': str}, getcallargs_forhints(str.upper, str))
+    # str.strip has an optional second argument.
+    self.assertEqual({
+        'self': str, 'chars': Any
+    },
+                     getcallargs_forhints(str.strip, str))
+    self.assertEqual({
+        'self': str, 'iterable': typehints.List[int]
+    },
+                     getcallargs_forhints(str.join, str, typehints.List[int]))
 
 
 class TestGetYieldedType(unittest.TestCase):

Reply via email to