Skip to content

Commit

Permalink
Drop support for Python 3.7
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 704275105
  • Loading branch information
oprypin authored and copybara-github committed Dec 9, 2024
1 parent 7b4b0e2 commit f9f47ec
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 113 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- python-version: "3.7"
os: macos-latest # arm64
include:
- python-version: "3.7"
os: macos-13 # x64

steps:
- uses: actions/checkout@v4
Expand Down
39 changes: 19 additions & 20 deletions absl/flags/_defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import enum
import sys
import types
import typing
from typing import Any, Iterable, List, Optional, Type, TypeVar, Union, overload
from typing import Any, Iterable, List, Literal, Optional, Type, TypeVar, Union, overload

from absl.flags import _argument_parser
from absl.flags import _exceptions
Expand Down Expand Up @@ -65,7 +64,7 @@ def DEFINE( # pylint: disable=invalid-name
flag_values: _flagvalues.FlagValues = ...,
serializer: Optional[_argument_parser.ArgumentSerializer[_T]] = ...,
module_name: Optional[str] = ...,
required: 'typing.Literal[True]' = ...,
required: Literal[True] = ...,
**args: Any
) -> _flagvalues.FlagHolder[_T]:
...
Expand Down Expand Up @@ -134,7 +133,7 @@ def DEFINE_flag( # pylint: disable=invalid-name
flag: _flag.Flag[_T],
flag_values: _flagvalues.FlagValues = ...,
module_name: Optional[str] = ...,
required: 'typing.Literal[True]' = ...,
required: Literal[True] = ...,
) -> _flagvalues.FlagHolder[_T]:
...

Expand Down Expand Up @@ -374,7 +373,7 @@ def DEFINE_string( # pylint: disable=invalid-name
help: Optional[str], # pylint: disable=redefined-builtin
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[str]:
...
Expand Down Expand Up @@ -435,7 +434,7 @@ def DEFINE_boolean( # pylint: disable=invalid-name
flag_values: _flagvalues.FlagValues = ...,
module_name: Optional[str] = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[bool]:
...
Expand Down Expand Up @@ -518,7 +517,7 @@ def DEFINE_float( # pylint: disable=invalid-name
upper_bound: Optional[float] = ...,
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[float]:
...
Expand Down Expand Up @@ -607,7 +606,7 @@ def DEFINE_integer( # pylint: disable=invalid-name
upper_bound: Optional[int] = ...,
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[int]:
...
Expand Down Expand Up @@ -696,7 +695,7 @@ def DEFINE_enum( # pylint: disable=invalid-name
flag_values: _flagvalues.FlagValues = ...,
module_name: Optional[str] = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[str]:
...
Expand Down Expand Up @@ -781,7 +780,7 @@ def DEFINE_enum_class( # pylint: disable=invalid-name
module_name: Optional[str] = ...,
case_sensitive: bool = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[_ET]:
...
Expand Down Expand Up @@ -867,7 +866,7 @@ def DEFINE_list( # pylint: disable=invalid-name
help: str, # pylint: disable=redefined-builtin
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[str]]:
...
Expand Down Expand Up @@ -945,7 +944,7 @@ def DEFINE_spaceseplist( # pylint: disable=invalid-name
comma_compat: bool = ...,
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[str]]:
...
Expand Down Expand Up @@ -1032,7 +1031,7 @@ def DEFINE_multi( # pylint: disable=invalid-name
flag_values: _flagvalues.FlagValues = ...,
module_name: Optional[str] = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[_T]]:
...
Expand All @@ -1048,7 +1047,7 @@ def DEFINE_multi( # pylint: disable=invalid-name
flag_values: _flagvalues.FlagValues = ...,
module_name: Optional[str] = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[_T]]:
...
Expand Down Expand Up @@ -1156,7 +1155,7 @@ def DEFINE_multi_string( # pylint: disable=invalid-name
help: str, # pylint: disable=redefined-builtin
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[str]]:
...
Expand Down Expand Up @@ -1240,7 +1239,7 @@ def DEFINE_multi_integer( # pylint: disable=invalid-name
upper_bound: Optional[int] = ...,
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[int]]:
...
Expand Down Expand Up @@ -1331,7 +1330,7 @@ def DEFINE_multi_float( # pylint: disable=invalid-name
upper_bound: Optional[float] = ...,
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[float]]:
...
Expand Down Expand Up @@ -1421,7 +1420,7 @@ def DEFINE_multi_enum( # pylint: disable=invalid-name
help: str, # pylint: disable=redefined-builtin
flag_values: _flagvalues.FlagValues = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[str]]:
...
Expand Down Expand Up @@ -1515,7 +1514,7 @@ def DEFINE_multi_enum_class( # pylint: disable=invalid-name
flag_values: _flagvalues.FlagValues = ...,
module_name: Optional[str] = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[_ET]]:
...
Expand All @@ -1530,7 +1529,7 @@ def DEFINE_multi_enum_class( # pylint: disable=invalid-name
flag_values: _flagvalues.FlagValues = ...,
module_name: Optional[str] = ...,
*,
required: 'typing.Literal[True]',
required: Literal[True],
**args: Any
) -> _flagvalues.FlagHolder[List[_ET]]:
...
Expand Down
13 changes: 2 additions & 11 deletions absl/logging/tests/logging_functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@
W0000 23:59:59.000000 12345 logging_functional_test_helper.py:82] Warn 4 (every 3)
"""

if sys.version_info[0:2] == (3, 4):
_FAKE_ERROR_EXTRA_MESSAGE = """\
Traceback (most recent call last):
File "logging_functional_test_helper.py", line 456, in _test_do_logging
raise OSError('Fake Error')
"""
else:
_FAKE_ERROR_EXTRA_MESSAGE = ''

_PY_ERROR_LOG_MESSAGE = """\
E1231 23:59:59.000000 12345 logging_functional_test_helper.py:65] This line is VLOG level -2
E1231 23:59:59.000000 12345 logging_functional_test_helper.py:65] This line is log level -2
Expand All @@ -147,13 +138,13 @@
raise OSError('Fake Error')
OSError: Fake Error
E0000 00:00:00.000000 12345 logging_functional_test_helper.py:123] No traceback
{fake_error_extra}OSError: Fake Error
OSError: Fake Error
E1231 23:59:59.000000 12345 logging_functional_test_helper.py:90] Alarming Stuff
E0000 23:59:59.000000 12345 logging_functional_test_helper.py:92] Error first 1 of 2
E0000 23:59:59.000000 12345 logging_functional_test_helper.py:93] Error 1 (every 3)
E0000 23:59:59.000000 12345 logging_functional_test_helper.py:92] Error first 2 of 2
E0000 23:59:59.000000 12345 logging_functional_test_helper.py:93] Error 4 (every 3)
""".format(fake_error_extra=_FAKE_ERROR_EXTRA_MESSAGE)
"""


_CRITICAL_DOWNGRADE_TO_ERROR_MESSAGE = """\
Expand Down
4 changes: 1 addition & 3 deletions absl/testing/absltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2432,9 +2432,7 @@ def _setup_filtering(argv: MutableSequence[str]) -> bool:
if argv is None or not test_filter:
return False

filters = shlex.split(test_filter)
if sys.version_info[:2] >= (3, 7):
filters = ['-k=' + test_filter for test_filter in filters]
filters = ['-k=' + test_filter for test_filter in shlex.split(test_filter)]

argv[1:1] = filters
return True
Expand Down
37 changes: 3 additions & 34 deletions absl/testing/tests/absltest_filtering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ def _run_filtered(self, test_filter, use_env_variable, use_app_run):
if use_env_variable:
env['TESTBRIDGE_TEST_ONLY'] = test_filter
elif test_filter:
if sys.version_info[:2] >= (3, 7):
# The -k flags are passed as positional arguments to absl.flags.
additional_args.append('--')
additional_args.extend(['-k=' + f for f in test_filter.split(' ')])
else:
additional_args.extend(test_filter.split(' '))
# The -k flags are passed as positional arguments to absl.flags.
additional_args.append('--')
additional_args.extend(['-k=' + f for f in test_filter.split(' ')])

proc = subprocess.Popen(
args=([_bazelize_command.get_executable_path(self._test_name)] +
Expand Down Expand Up @@ -117,9 +114,6 @@ def test_multiple_class_and_method_filter(self, use_env_variable,
self.assertIn('class B test C', out)
self.assertNotIn('class B test A', out)

@absltest.skipIf(
sys.version_info[:2] < (3, 7),
'Only Python 3.7+ does glob and substring matching.')
def test_substring(self, use_env_variable, use_app_run):
out, exit_code = self._run_filtered(
'testA', use_env_variable, use_app_run)
Expand All @@ -128,9 +122,6 @@ def test_substring(self, use_env_variable, use_app_run):
self.assertIn('ClassA.testA', out)
self.assertIn('ClassB.testA', out)

@absltest.skipIf(
sys.version_info[:2] < (3, 7),
'Only Python 3.7+ does glob and substring matching.')
def test_glob_pattern(self, use_env_variable, use_app_run):
out, exit_code = self._run_filtered(
'__main__.Class*.testA', use_env_variable, use_app_run)
Expand All @@ -139,20 +130,6 @@ def test_glob_pattern(self, use_env_variable, use_app_run):
self.assertIn('ClassA.testA', out)
self.assertIn('ClassB.testA', out)

@absltest.skipIf(
sys.version_info[:2] >= (3, 7),
"Python 3.7+ uses unittest's -k flag and doesn't fail if no tests match.")
def test_not_found_filters_py36(self, use_env_variable, use_app_run):
out, exit_code = self._run_filtered('NotExistedClass.not_existed_method',
use_env_variable, use_app_run)
self.assertEqual(1, exit_code)
self.assertIn("has no attribute 'NotExistedClass'", out)

@absltest.skipIf(
sys.version_info[:2] < (3, 7),
'Python 3.6 passes the filter as positional arguments and fails if no '
'tests match.'
)
def test_not_found_filters_py37(self, use_env_variable, use_app_run):
out, exit_code = self._run_filtered('NotExistedClass.not_existed_method',
use_env_variable, use_app_run)
Expand All @@ -164,10 +141,6 @@ def test_not_found_filters_py37(self, use_env_variable, use_app_run):
self.assertEqual(0, exit_code)
self.assertIn('Ran 0 tests', out)

@absltest.skipIf(
sys.version_info[:2] < (3, 7),
'Python 3.6 passes the filter as positional arguments and matches by name'
)
def test_parameterized_unnamed(self, use_env_variable, use_app_run):
out, exit_code = self._run_filtered('ParameterizedTest.test_unnamed',
use_env_variable, use_app_run)
Expand All @@ -176,10 +149,6 @@ def test_parameterized_unnamed(self, use_env_variable, use_app_run):
self.assertIn('parameterized unnamed 1', out)
self.assertIn('parameterized unnamed 2', out)

@absltest.skipIf(
sys.version_info[:2] < (3, 7),
'Python 3.6 passes the filter as positional arguments and matches by name'
)
def test_parameterized_named(self, use_env_variable, use_app_run):
out, exit_code = self._run_filtered('ParameterizedTest.test_named',
use_env_variable, use_app_run)
Expand Down
2 changes: 0 additions & 2 deletions absl/testing/tests/absltest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,6 @@ def test_enter_context(self):
self.assertEqual(self.cm_state, 'yielded')


@absltest.skipIf(not hasattr(absltest.TestCase, 'addClassCleanup'),
'Python 3.8 required for class-level enter_context')
class EnterContextClassmethodTest(absltest.TestCase):

cm_state = 'unset'
Expand Down
45 changes: 19 additions & 26 deletions absl/testing/tests/parameterized_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,6 @@ def test_name(self, name):
class SubclassTestCase(SuperclassTestCase):
pass

@unittest.skipIf(
(sys.version_info[:2] == (3, 7) and sys.version_info[2] in {0, 1, 2}),
'Python 3.7.0 to 3.7.2 have a bug that breaks this test, see '
'https://bugs.python.org/issue35767',
)
def test_missing_inheritance(self):
ts = unittest.defaultTestLoader.loadTestsFromTestCase(
self.BadAdditionParams
Expand Down Expand Up @@ -1054,33 +1049,31 @@ def test_subclass_inherits_superclass_test_params_reprs(self):
)


# IsolatedAsyncioTestCase is only available in Python 3.8+.
if sys.version_info[:2] >= (3, 8):
async def mult(x: float, y: float) -> float:
return x * y

async def mult(x: float, y: float) -> float:
return x * y

class AsyncTest(unittest.IsolatedAsyncioTestCase, parameterized.TestCase):
class AsyncTest(unittest.IsolatedAsyncioTestCase, parameterized.TestCase):

def setUp(self):
super().setUp()
self.verify_ran = False
def setUp(self):
super().setUp()
self.verify_ran = False

def tearDown(self):
super().tearDown()
def tearDown(self):
super().tearDown()

# We need the additional check here because originally the test function
# would run, but a coroutine results from the execution and is never
# awaited, so it looked like a successful test run when in fact the
# internal test logic never executed. If you remove the check for
# coroutine and run_until_complete, then set the parameters to fail they
# never will.
self.assertTrue(self.verify_ran)
# We need the additional check here because originally the test function
# would run, but a coroutine results from the execution and is never
# awaited, so it looked like a successful test run when in fact the
# internal test logic never executed. If you remove the check for
# coroutine and run_until_complete, then set the parameters to fail they
# never will.
self.assertTrue(self.verify_ran)

@parameterized.parameters((1, 2, 2), (2, 2, 4), (3, 2, 6))
async def test_multiply_expected_matches_actual(self, x, y, expected):
self.assertEqual(await mult(x, y), expected)
self.verify_ran = True
@parameterized.parameters((1, 2, 2), (2, 2, 4), (3, 2, 6))
async def test_multiply_expected_matches_actual(self, x, y, expected):
self.assertEqual(await mult(x, y), expected)
self.verify_ran = True


def _decorate_with_side_effects(func, self):
Expand Down
Loading

0 comments on commit f9f47ec

Please sign in to comment.