Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More typehints #1514

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bleak/backends/characteristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_descriptor(
raise NotImplementedError()

@abc.abstractmethod
def add_descriptor(self, descriptor: BleakGATTDescriptor):
def add_descriptor(self, descriptor: BleakGATTDescriptor) -> None:
"""Add a :py:class:`~BleakGATTDescriptor` to the characteristic.

Should not be used by end user, but rather by `bleak` itself.
Expand Down
4 changes: 2 additions & 2 deletions bleak/backends/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def register_detection_callback(

if inspect.iscoroutinefunction(callback):

def detection_callback(s, d):
def detection_callback(s: BLEDevice, d: AdvertisementData) -> None:
task = asyncio.create_task(callback(s, d))
_background_tasks.add(task)
task.add_done_callback(_background_tasks.discard)
Expand All @@ -192,7 +192,7 @@ def detection_callback(s, d):

self._ad_callbacks[token] = detection_callback

def remove():
def remove() -> None:
self._ad_callbacks.pop(token, None)

return remove
Expand Down
16 changes: 8 additions & 8 deletions bleak/backends/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import abc
import logging
from typing import Dict, Iterator, List, Optional, Union
from typing import Any, Dict, Iterator, List, Optional, Union
from uuid import UUID

from ..exc import BleakError
Expand All @@ -21,10 +21,10 @@
class BleakGATTService(abc.ABC):
"""Interface for the Bleak representation of a GATT Service."""

def __init__(self, obj):
def __init__(self, obj: Any) -> None:
self.obj = obj

def __str__(self):
def __str__(self) -> str:
return f"{self.uuid} (Handle: {self.handle}): {self.description}"

@property
Expand All @@ -51,7 +51,7 @@ def characteristics(self) -> List[BleakGATTCharacteristic]:
raise NotImplementedError()

@abc.abstractmethod
def add_characteristic(self, characteristic: BleakGATTCharacteristic):
def add_characteristic(self, characteristic: BleakGATTCharacteristic) -> None:
"""Add a :py:class:`~BleakGATTCharacteristic` to the service.

Should not be used by end user, but rather by `bleak` itself.
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_characteristic(
class BleakGATTServiceCollection:
"""Simple data container for storing the peripheral's service complement."""

def __init__(self):
def __init__(self) -> None:
self.__services = {}
self.__characteristics = {}
self.__descriptors = {}
Expand Down Expand Up @@ -117,7 +117,7 @@ def descriptors(self) -> Dict[int, BleakGATTDescriptor]:
"""Returns a dictionary of integer handles mapping to BleakGATTDescriptor"""
return self.__descriptors

def add_service(self, service: BleakGATTService):
def add_service(self, service: BleakGATTService) -> None:
"""Add a :py:class:`~BleakGATTService` to the service collection.

Should not be used by end user, but rather by `bleak` itself.
Expand Down Expand Up @@ -153,7 +153,7 @@ def get_service(

return x[0] if x else None

def add_characteristic(self, characteristic: BleakGATTCharacteristic):
def add_characteristic(self, characteristic: BleakGATTCharacteristic) -> None:
"""Add a :py:class:`~BleakGATTCharacteristic` to the service collection.

Should not be used by end user, but rather by `bleak` itself.
Expand Down Expand Up @@ -191,7 +191,7 @@ def get_characteristic(

return x[0] if x else None

def add_descriptor(self, descriptor: BleakGATTDescriptor):
def add_descriptor(self, descriptor: BleakGATTDescriptor) -> None:
"""Add a :py:class:`~BleakGATTDescriptor` to the service collection.

Should not be used by end user, but rather by `bleak` itself.
Expand Down
2 changes: 1 addition & 1 deletion bleak/uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@
}


def uuidstr_to_str(uuid_):
def uuidstr_to_str(uuid_: str) -> str:
uuid_ = uuid_.lower()
s = uuid128_dict.get(uuid_)
if s:
Expand Down
Loading