diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 830ca0f4..5283b586 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -64,12 +64,15 @@ jobs: fail-fast: false matrix: python-version: - - "pypy-3.9" - "pypy-3.10" - - "3.9" + - "pypy-3.11" + - "pypy-3.12" - "3.10" - "3.11" - "3.12" + - "3.13" + - "3.14" + - "3.15" steps: - uses: actions/checkout@v3 with: @@ -92,13 +95,13 @@ jobs: fail-fast: false matrix: python-version: - # disabled due to librt is not available on this pypy version - # - "pypy-3.9" - # - "pypy-3.10" - # - "3.9" - # - "3.10" + # CPython only: mypy depends on librt, which publishes no PyPy wheels + - "3.10" - "3.11" - "3.12" + - "3.13" + - "3.14" + - "3.15" steps: - uses: actions/checkout@v3 with: diff --git a/README.md b/README.md index e0aeafb6..13df31e3 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ Version `4.0+`: Python 3.7+, PyPy 3.7+ Version `3.0+`: Python 2.7+, PyPy 3.4+ +Dropping support for an end-of-life Python version doesn't change the SDK's public API, so it ships in a minor release rather than a major one. Each release declares its minimum Python (`python_requires`), so pip on an older Python installs the last compatible release instead. For example, Python 3.8 and 3.9 stay on 5.8.x. + ### Install the SDK The SDK is available through [PyPi](https://pypi.python.org/pypi?name=optimizely-sdk&:action=display). diff --git a/optimizely/event/event_id_normalizer.py b/optimizely/event/event_id_normalizer.py index f2d4235d..5bf7103e 100644 --- a/optimizely/event/event_id_normalizer.py +++ b/optimizely/event/event_id_normalizer.py @@ -37,13 +37,7 @@ """ -from sys import version_info -from typing import Any, Optional - -if version_info < (3, 10): - from typing_extensions import TypeGuard -else: - from typing import TypeGuard +from typing import Any, Optional, TypeGuard def is_non_empty_string(value: Any) -> TypeGuard[str]: diff --git a/ruff.toml b/ruff.toml index 5365a7b4..289c7c59 100644 --- a/ruff.toml +++ b/ruff.toml @@ -2,7 +2,7 @@ # https://docs.astral.sh/ruff/configuration/ line-length = 120 -target-version = "py39" +target-version = "py310" exclude = [ ".git", diff --git a/setup.py b/setup.py index 18c9d1d7..8aac986a 100644 --- a/setup.py +++ b/setup.py @@ -52,14 +52,16 @@ 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', + 'Programming Language :: Python :: 3.14', + 'Programming Language :: Python :: 3.15', ], packages=find_packages(exclude=['docs', 'tests']), extras_require={'test': TEST_REQUIREMENTS}, + python_requires='>=3.10', install_requires=REQUIREMENTS, tests_require=TEST_REQUIREMENTS, test_suite='tests', diff --git a/tests/test_config_manager.py b/tests/test_config_manager.py index 8fa19693..96bb5ecb 100644 --- a/tests/test_config_manager.py +++ b/tests/test_config_manager.py @@ -556,32 +556,24 @@ def test_fetch_datafile__request_exception_raised(self, _): def test_fetch_datafile__exception_polling_thread_failed(self, _): """ Test that exception is raised when polling thread stops. """ - sdk_key = 'some_key' mock_logger = mock.Mock() + thread_exceptions = [] - test_headers = {'Last-Modified': 'New Time'} - test_datafile = json.dumps(self.config_dict_with_features) - test_response = requests.Response() - test_response.status_code = 200 - test_response.headers = test_headers - test_response._content = test_datafile - - with mock.patch('requests.Session.get', return_value=test_response): - project_config_manager = config_manager.PollingConfigManager(sdk_key=sdk_key, - logger=mock_logger, - update_interval=12345678912345) + with ( + mock.patch('optimizely.config_manager.PollingConfigManager.fetch_datafile', + side_effect=Exception('boom')), + mock.patch('threading.excepthook', side_effect=thread_exceptions.append), + ): + project_config_manager = config_manager.PollingConfigManager(sdk_key='some_key', logger=mock_logger) + project_config_manager._polling_thread.join(timeout=2) - project_config_manager.stop() + # the exception is raised out of the polling thread, which stops + self.assertFalse(project_config_manager.is_running) + self.assertEqual(1, len(thread_exceptions)) + self.assertEqual('boom', str(thread_exceptions[0].exc_value)) - # verify the error log message - log_messages = [args[0] for args, _ in mock_logger.error.call_args_list] - for message in log_messages: - print(message) - # Check for key parts of the error message (version-agnostic for Python 3.11+) - if not ("Thread for background datafile polling failed" in message and - "timestamp too large to convert to C" in message and - "PyTime_t" in message): - assert False + # and it is logged before being raised + mock_logger.error.assert_called_once_with('Thread for background datafile polling failed. Error: boom') def test_is_running(self, _): """ Test that polling thread is running after instance of PollingConfigManager is created. """