From 84a6453dda6cb323c394fcf31f38eb31662278bb Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Thu, 15 Jan 2026 12:06:05 +0800 Subject: [PATCH] Fix GATT TemplateSerivce annotations --- bumble/device.py | 5 +---- bumble/gatt.py | 4 ++-- bumble/gatt_client.py | 7 +++++-- bumble/profiles/battery_service.py | 5 +---- bumble/profiles/heart_rate_service.py | 17 ++++++----------- tests/heart_rate_service_test.py | 2 +- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/bumble/device.py b/bumble/device.py index a0e41b9..82af722 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -1383,10 +1383,7 @@ class Peer: def create_service_proxy( self, proxy_class: type[_PROXY_CLASS] ) -> _PROXY_CLASS | None: - if proxy := proxy_class.from_client(self.gatt_client): - return cast(_PROXY_CLASS, proxy) - - return None + return proxy_class.from_client(self.gatt_client) async def discover_service_and_create_proxy( self, proxy_class: type[_PROXY_CLASS] diff --git a/bumble/gatt.py b/bumble/gatt.py index 11a8378..371255e 100644 --- a/bumble/gatt.py +++ b/bumble/gatt.py @@ -29,7 +29,7 @@ import functools import logging import struct from collections.abc import Iterable, Sequence -from typing import TypeVar +from typing import ClassVar, TypeVar from bumble.att import Attribute, AttributeValue, AttributeValueV2 from bumble.colors import color @@ -403,7 +403,7 @@ class TemplateService(Service): to expose their UUID as a class property ''' - UUID: UUID + UUID: ClassVar[UUID] def __init__( self, diff --git a/bumble/gatt_client.py b/bumble/gatt_client.py index 8782366..7656424 100644 --- a/bumble/gatt_client.py +++ b/bumble/gatt_client.py @@ -34,11 +34,14 @@ from datetime import datetime from typing import ( TYPE_CHECKING, Any, + ClassVar, Generic, TypeVar, overload, ) +from typing_extensions import Self + from bumble import att, core, l2cap, utils from bumble.colors import color from bumble.core import UUID, InvalidStateError @@ -249,10 +252,10 @@ class ProfileServiceProxy: Base class for profile-specific service proxies ''' - SERVICE_CLASS: type[TemplateService] + SERVICE_CLASS: ClassVar[type[TemplateService]] @classmethod - def from_client(cls, client: Client) -> ProfileServiceProxy | None: + def from_client(cls, client: Client) -> Self | None: return ServiceProxy.from_client(cls, client, cls.SERVICE_CLASS.UUID) diff --git a/bumble/profiles/battery_service.py b/bumble/profiles/battery_service.py index 765f4a0..7c1c3c4 100644 --- a/bumble/profiles/battery_service.py +++ b/bumble/profiles/battery_service.py @@ -18,10 +18,7 @@ # ----------------------------------------------------------------------------- from collections.abc import Callable -from bumble import device -from bumble import gatt -from bumble import gatt_adapters -from bumble import gatt_client +from bumble import device, gatt, gatt_adapters, gatt_client # ----------------------------------------------------------------------------- diff --git a/bumble/profiles/heart_rate_service.py b/bumble/profiles/heart_rate_service.py index ca02894..ffd7b23 100644 --- a/bumble/profiles/heart_rate_service.py +++ b/bumble/profiles/heart_rate_service.py @@ -19,19 +19,14 @@ from __future__ import annotations import dataclasses -from typing import Any -from typing_extensions import Self -from collections.abc import Sequence, Callable -import struct import enum +import struct +from collections.abc import Callable, Sequence +from typing import Any -from bumble import core -from bumble import device -from bumble import utils -from bumble import att -from bumble import gatt -from bumble import gatt_adapters -from bumble import gatt_client +from typing_extensions import Self + +from bumble import att, core, device, gatt, gatt_adapters, gatt_client, utils # ----------------------------------------------------------------------------- diff --git a/tests/heart_rate_service_test.py b/tests/heart_rate_service_test.py index bfc0a1a..274e329 100644 --- a/tests/heart_rate_service_test.py +++ b/tests/heart_rate_service_test.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from collections.abc import Sequence import asyncio import itertools +from collections.abc import Sequence import pytest