From 33d1880ead03d766750a9bfa917c2d26e0d59eaa Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 9 Aug 2023 14:10:38 -0500 Subject: [PATCH] drop support for Python 3.7 Python 3.7 has reached end of life. --- .github/pull_request_template.md | 2 +- .github/workflows/build_and_test.yml | 2 +- CHANGELOG.rst | 4 ++ CONTRIBUTING.rst | 2 +- bleak/__init__.py | 5 +- bleak/backends/bluezdbus/defs.py | 8 +-- bleak/backends/bluezdbus/scanner.py | 8 +-- bleak/backends/corebluetooth/scanner.py | 8 +-- bleak/backends/p4android/scanner.py | 7 +-- bleak/backends/winrt/client.py | 29 +++++---- bleak/backends/winrt/scanner.py | 8 +-- poetry.lock | 59 +------------------ pyproject.toml | 7 +-- .../bleak/backends/bluezdbus/test_version.py | 8 +-- 14 files changed, 37 insertions(+), 120 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 28918d22..33e3fb6e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,7 +6,7 @@ Before you submit a pull request, check that it meets these guidelines: 1. If the pull request adds functionality, the docs should be updated. 2. Modify the `CHANGELOG.rst`, describing your changes as is specified by the guidelines in that document. -3. The pull request should work for Python 3.7+ on the following platforms: +3. The pull request should work for Python 3.8+ on the following platforms: - Windows 10, version 16299 (Fall Creators Update) and greater - Linux distributions with BlueZ >= 5.43 - OS X / macOS >= 10.11 diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index ea19753b..e7266056 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11'] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 735ab3d7..d7cd7ea4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -39,6 +39,10 @@ Fixed * Optimize BlueZ backend device watchers and condition callbacks to avoid linear searches * Fixed WinRT backend sometimes hanging forever when a device goes out of range during connection. Fixes #1359. +Removed +------- +Dropped support for Python 3.7. + `0.20.2`_ (2023-04-19) ====================== diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 6e437bcc..9299ac6f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -101,7 +101,7 @@ Before you submit a pull request, check that it meets these guidelines: 1. If the pull request adds functionality, the docs should be updated. 2. Modify the ``CHANGELOG.rst``, describing your changes as is specified by the guidelines in that document. -3. The pull request should work for Python 3.7+ on the following platforms: +3. The pull request should work for Python 3.8+ on the following platforms: - Windows 10, version 16299 (Fall Creators Update) and greater - Linux distributions with BlueZ >= 5.43 - OS X / macOS >= 10.11 diff --git a/bleak/__init__.py b/bleak/__init__.py index b6be9dd4..8a467203 100644 --- a/bleak/__init__.py +++ b/bleak/__init__.py @@ -30,6 +30,7 @@ overload, ) from warnings import warn +from typing import Literal if sys.version_info < (3, 12): from typing_extensions import Buffer @@ -41,10 +42,6 @@ else: from asyncio import timeout as async_timeout -if sys.version_info[:2] < (3, 8): - from typing_extensions import Literal -else: - from typing import Literal from .backends.characteristic import BleakGATTCharacteristic from .backends.client import BaseBleakClient, get_platform_client_backend_type diff --git a/bleak/backends/bluezdbus/defs.py b/bleak/backends/bluezdbus/defs.py index 8ec19af2..50054540 100644 --- a/bleak/backends/bluezdbus/defs.py +++ b/bleak/backends/bluezdbus/defs.py @@ -1,12 +1,6 @@ # -*- coding: utf-8 -*- -import sys -from typing import Dict, List, Tuple - -if sys.version_info[:2] < (3, 8): - from typing_extensions import Literal, TypedDict -else: - from typing import Literal, TypedDict +from typing import Dict, List, Literal, Tuple, TypedDict # DBus Interfaces OBJECT_MANAGER_INTERFACE = "org.freedesktop.DBus.ObjectManager" diff --git a/bleak/backends/bluezdbus/scanner.py b/bleak/backends/bluezdbus/scanner.py index 4f0bdbe8..24591398 100644 --- a/bleak/backends/bluezdbus/scanner.py +++ b/bleak/backends/bluezdbus/scanner.py @@ -1,15 +1,9 @@ import logging -import sys -from typing import Callable, Coroutine, Dict, List, Optional +from typing import Callable, Coroutine, Dict, List, Literal, Optional, TypedDict from warnings import warn from dbus_fast import Variant -if sys.version_info[:2] < (3, 8): - from typing_extensions import Literal, TypedDict -else: - from typing import Literal, TypedDict - from ...exc import BleakError from ..scanner import AdvertisementData, AdvertisementDataCallback, BaseBleakScanner from .advertisement_monitor import OrPatternLike diff --git a/bleak/backends/corebluetooth/scanner.py b/bleak/backends/corebluetooth/scanner.py index b3ef1603..e6d20c2d 100644 --- a/bleak/backends/corebluetooth/scanner.py +++ b/bleak/backends/corebluetooth/scanner.py @@ -1,11 +1,5 @@ import logging -import sys -from typing import Any, Dict, List, Optional - -if sys.version_info[:2] < (3, 8): - from typing_extensions import Literal, TypedDict -else: - from typing import Literal, TypedDict +from typing import Any, Dict, List, Literal, Optional, TypedDict import objc from CoreBluetooth import CBPeripheral diff --git a/bleak/backends/p4android/scanner.py b/bleak/backends/p4android/scanner.py index 496034c4..e53662f6 100644 --- a/bleak/backends/p4android/scanner.py +++ b/bleak/backends/p4android/scanner.py @@ -4,18 +4,13 @@ import logging import sys import warnings -from typing import List, Optional +from typing import List, Literal, Optional if sys.version_info < (3, 11): from async_timeout import timeout as async_timeout else: from asyncio import timeout as async_timeout -if sys.version_info[:2] < (3, 8): - from typing_extensions import Literal -else: - from typing import Literal - from android.broadcast import BroadcastReceiver from android.permissions import Permission, request_permissions from jnius import cast, java_method diff --git a/bleak/backends/winrt/client.py b/bleak/backends/winrt/client.py index 6f5455d5..882fb696 100644 --- a/bleak/backends/winrt/client.py +++ b/bleak/backends/winrt/client.py @@ -11,7 +11,19 @@ import uuid import warnings from ctypes import WinError -from typing import Any, Dict, List, Optional, Sequence, Set, Union, cast +from typing import ( + Any, + Dict, + List, + Literal, + Optional, + Protocol, + Sequence, + Set, + TypedDict, + Union, + cast, +) if sys.version_info < (3, 12): from typing_extensions import Buffer @@ -23,11 +35,6 @@ else: from asyncio import timeout as async_timeout -if sys.version_info[:2] < (3, 8): - from typing_extensions import Literal, TypedDict -else: - from typing import Literal, TypedDict - from bleak_winrt.windows.devices.bluetooth import ( BluetoothAddressType, BluetoothCacheMode, @@ -73,10 +80,10 @@ logger = logging.getLogger(__name__) -# TODO: we can use this when minimum Python is 3.8 -# class _Result(typing.Protocol): -# status: GattCommunicationStatus -# protocol_error: typing.Optional[int] + +class _Result(Protocol): + status: GattCommunicationStatus + protocol_error: int def _address_to_int(address: str) -> int: @@ -95,7 +102,7 @@ def _address_to_int(address: str) -> int: return int(address, base=16) -def _ensure_success(result: Any, attr: Optional[str], fail_msg: str) -> Any: +def _ensure_success(result: _Result, attr: Optional[str], fail_msg: str) -> Any: """ Ensures that *status* is ``GattCommunicationStatus.SUCCESS``, otherwise raises ``BleakError``. diff --git a/bleak/backends/winrt/scanner.py b/bleak/backends/winrt/scanner.py index 8c81df55..acb02f52 100644 --- a/bleak/backends/winrt/scanner.py +++ b/bleak/backends/winrt/scanner.py @@ -1,7 +1,6 @@ import asyncio import logging -import sys -from typing import Dict, List, NamedTuple, Optional +from typing import Dict, List, Literal, NamedTuple, Optional from uuid import UUID from bleak_winrt.windows.devices.bluetooth.advertisement import ( @@ -12,11 +11,6 @@ BluetoothLEScanningMode, ) -if sys.version_info[:2] < (3, 8): - from typing_extensions import Literal -else: - from typing import Literal - from ...assigned_numbers import AdvertisementDataType from ...uuids import normalize_uuid_str from ..scanner import AdvertisementData, AdvertisementDataCallback, BaseBleakScanner diff --git a/poetry.lock b/poetry.lock index e35ecddd..029b2713 100644 --- a/poetry.lock +++ b/poetry.lock @@ -22,20 +22,6 @@ files = [ {file = "async_timeout-4.0.2-py3-none-any.whl", hash = "sha256:8ca1e4fcf50d07413d66d1a5e416e42cfdf5851c981d679a09851a6853383b3c"}, ] -[package.dependencies] -typing-extensions = {version = ">=3.6.5", markers = "python_version < \"3.8\""} - -[[package]] -name = "asynctest" -version = "0.13.0" -description = "Enhance the standard unittest package with features for testing asyncio libraries" -optional = false -python-versions = ">=3.5" -files = [ - {file = "asynctest-0.13.0-py3-none-any.whl", hash = "sha256:5da6118a7e6d6b54d83a8f7197769d046922a44d2a99c21382f0a6e4fadae676"}, - {file = "asynctest-0.13.0.tar.gz", hash = "sha256:c27862842d15d83e6a34eb0b2866c323880eb3a75e4485b079ea11748fd77fac"}, -] - [[package]] name = "attrs" version = "22.1.0" @@ -105,7 +91,6 @@ mypy-extensions = ">=0.4.3" pathspec = ">=0.9.0" platformdirs = ">=2" tomli = {version = ">=1.1.0", markers = "python_full_version < \"3.11.0a7\""} -typed-ast = {version = ">=1.4.2", markers = "python_version < \"3.8\" and implementation_name == \"cpython\""} typing-extensions = {version = ">=3.10.0.0", markers = "python_version < \"3.10\""} [package.extras] @@ -172,7 +157,6 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "platform_system == \"Windows\""} -importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} [[package]] name = "colorama" @@ -351,7 +335,6 @@ files = [ ] [package.dependencies] -typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] @@ -509,9 +492,6 @@ files = [ {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, ] -[package.dependencies] -importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} - [package.extras] dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] @@ -662,7 +642,6 @@ files = [ [package.dependencies] attrs = ">=19.2.0" colorama = {version = "*", markers = "sys_platform == \"win32\""} -importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} iniconfig = "*" packaging = "*" pluggy = ">=0.12,<2.0" @@ -685,7 +664,6 @@ files = [ [package.dependencies] pytest = ">=6.1.0" -typing-extensions = {version = ">=3.7.2", markers = "python_version < \"3.8\""} [package.extras] testing = ["coverage (>=6.2)", "flaky (>=3.5.0)", "hypothesis (>=5.7.1)", "mypy (>=0.931)", "pytest-trio (>=0.7.0)"] @@ -904,39 +882,6 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] -[[package]] -name = "typed-ast" -version = "1.5.4" -description = "a fork of Python 2 and 3 ast modules with type comment support" -optional = false -python-versions = ">=3.6" -files = [ - {file = "typed_ast-1.5.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:669dd0c4167f6f2cd9f57041e03c3c2ebf9063d0757dc89f79ba1daa2bfca9d4"}, - {file = "typed_ast-1.5.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:211260621ab1cd7324e0798d6be953d00b74e0428382991adfddb352252f1d62"}, - {file = "typed_ast-1.5.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:267e3f78697a6c00c689c03db4876dd1efdfea2f251a5ad6555e82a26847b4ac"}, - {file = "typed_ast-1.5.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:c542eeda69212fa10a7ada75e668876fdec5f856cd3d06829e6aa64ad17c8dfe"}, - {file = "typed_ast-1.5.4-cp310-cp310-win_amd64.whl", hash = "sha256:a9916d2bb8865f973824fb47436fa45e1ebf2efd920f2b9f99342cb7fab93f72"}, - {file = "typed_ast-1.5.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:79b1e0869db7c830ba6a981d58711c88b6677506e648496b1f64ac7d15633aec"}, - {file = "typed_ast-1.5.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a94d55d142c9265f4ea46fab70977a1944ecae359ae867397757d836ea5a3f47"}, - {file = "typed_ast-1.5.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:183afdf0ec5b1b211724dfef3d2cad2d767cbefac291f24d69b00546c1837fb6"}, - {file = "typed_ast-1.5.4-cp36-cp36m-win_amd64.whl", hash = "sha256:639c5f0b21776605dd6c9dbe592d5228f021404dafd377e2b7ac046b0349b1a1"}, - {file = "typed_ast-1.5.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:cf4afcfac006ece570e32d6fa90ab74a17245b83dfd6655a6f68568098345ff6"}, - {file = "typed_ast-1.5.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed855bbe3eb3715fca349c80174cfcfd699c2f9de574d40527b8429acae23a66"}, - {file = "typed_ast-1.5.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:6778e1b2f81dfc7bc58e4b259363b83d2e509a65198e85d5700dfae4c6c8ff1c"}, - {file = "typed_ast-1.5.4-cp37-cp37m-win_amd64.whl", hash = "sha256:0261195c2062caf107831e92a76764c81227dae162c4f75192c0d489faf751a2"}, - {file = "typed_ast-1.5.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2efae9db7a8c05ad5547d522e7dbe62c83d838d3906a3716d1478b6c1d61388d"}, - {file = "typed_ast-1.5.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7d5d014b7daa8b0bf2eaef684295acae12b036d79f54178b92a2b6a56f92278f"}, - {file = "typed_ast-1.5.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:370788a63915e82fd6f212865a596a0fefcbb7d408bbbb13dea723d971ed8bdc"}, - {file = "typed_ast-1.5.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:4e964b4ff86550a7a7d56345c7864b18f403f5bd7380edf44a3c1fb4ee7ac6c6"}, - {file = "typed_ast-1.5.4-cp38-cp38-win_amd64.whl", hash = "sha256:683407d92dc953c8a7347119596f0b0e6c55eb98ebebd9b23437501b28dcbb8e"}, - {file = "typed_ast-1.5.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4879da6c9b73443f97e731b617184a596ac1235fe91f98d279a7af36c796da35"}, - {file = "typed_ast-1.5.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3e123d878ba170397916557d31c8f589951e353cc95fb7f24f6bb69adc1a8a97"}, - {file = "typed_ast-1.5.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ebd9d7f80ccf7a82ac5f88c521115cc55d84e35bf8b446fcd7836eb6b98929a3"}, - {file = "typed_ast-1.5.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:98f80dee3c03455e92796b58b98ff6ca0b2a6f652120c263efdba4d6c5e58f72"}, - {file = "typed_ast-1.5.4-cp39-cp39-win_amd64.whl", hash = "sha256:0fdbcf2fef0ca421a3f5912555804296f0b0960f0418c440f5d6d3abb549f3e1"}, - {file = "typed_ast-1.5.4.tar.gz", hash = "sha256:39e21ceb7388e4bb37f4c679d72707ed46c2fbf2a5609b8b8ebc4b067d977df2"}, -] - [[package]] name = "typing-extensions" version = "4.7.1" @@ -981,5 +926,5 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>= [metadata] lock-version = "2.0" -python-versions = "^3.7" -content-hash = "15f2471def826aaaf402f7457ff40a9a5e4e02c8212e39988af1c19b5fad90cc" +python-versions = "^3.8" +content-hash = "5f227d158a9bd163e028e1ae0af8074ffa712cd07fea2b8d628e98e37a65e3f8" diff --git a/pyproject.toml b/pyproject.toml index 982a2e96..bd3a1166 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ classifiers = [ "Issues" = "https://github.com/hbldh/bleak/issues" [tool.poetry.dependencies] -python = "^3.7" +python = "^3.8" async-timeout = { version = ">= 3.0.0, < 5", python = "<3.11" } typing-extensions = { version = ">=4.7.0", python = "<3.12" } pyobjc-core = { version = "^9.0.1", markers = "platform_system=='Darwin'" } @@ -32,15 +32,14 @@ bleak-winrt = { version = "^1.2.0", markers = "platform_system=='Windows'" } dbus-fast = { version = "^1.83.0", markers = "platform_system == 'Linux'" } [tool.poetry.group.docs.dependencies] -Sphinx = { version = "^5.1.1", python = ">=3.8" } +Sphinx = "^5.1.1" sphinx-rtd-theme = "^1.0.0" [tool.poetry.group.lint.dependencies] black = "^22.1.0" -flake8 = { version = "^5.0.0", python = ">=3.8" } +flake8 = "^5.0.0" [tool.poetry.group.test.dependencies] -asynctest = { version = "^0.13.0", python = "<3.8" } pytest = "^7.0.0" pytest-asyncio = "^0.19.0" pytest-cov = "^3.0.0 " diff --git a/tests/bleak/backends/bluezdbus/test_version.py b/tests/bleak/backends/bluezdbus/test_version.py index afe3f1dc..6f36b7f5 100644 --- a/tests/bleak/backends/bluezdbus/test_version.py +++ b/tests/bleak/backends/bluezdbus/test_version.py @@ -2,16 +2,10 @@ """Tests for `bleak.backends.bluezdbus.version` package.""" -import sys -from unittest.mock import Mock, patch +from unittest.mock import AsyncMock, Mock, patch import pytest -if sys.version_info[:2] < (3, 8): - from asynctest.mock import CoroutineMock as AsyncMock -else: - from unittest.mock import AsyncMock - from bleak.backends.bluezdbus.version import BlueZFeatures