Skip to content

Commit d05d2ad

Browse files
committed
Type annotate characteristics/int.py
1 parent 6b267ed commit d05d2ad

File tree

1 file changed

+42
-17
lines changed
  • adafruit_ble/characteristics

1 file changed

+42
-17
lines changed

adafruit_ble/characteristics/int.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@
1010
1111
"""
1212

13+
from __future__ import annotations
14+
1315
from . import Attribute
1416
from . import StructCharacteristic
1517

18+
try:
19+
from typing import Optional, Type, Union, TYPE_CHECKING
20+
21+
if TYPE_CHECKING:
22+
from circuitpython_typing import ReadableBuffer
23+
from adafruit_ble.uuid import UUID
24+
from adafruit_ble.services import Service
25+
26+
except ImportError:
27+
pass
28+
1629
__version__ = "0.0.0-auto.0"
1730
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE.git"
1831

@@ -22,16 +35,16 @@ class IntCharacteristic(StructCharacteristic):
2235

2336
def __init__(
2437
self,
25-
format_string,
26-
min_value,
27-
max_value,
38+
format_string: str,
39+
min_value: int,
40+
max_value: int,
2841
*,
29-
uuid=None,
30-
properties=0,
31-
read_perm=Attribute.OPEN,
32-
write_perm=Attribute.OPEN,
33-
initial_value=None
34-
):
42+
uuid: Optional[UUID] = None,
43+
properties: int = 0,
44+
read_perm: int = Attribute.OPEN,
45+
write_perm: int = Attribute.OPEN,
46+
initial_value: Optional[ReadableBuffer] = None,
47+
) -> None:
3548
self._min_value = min_value
3649
self._max_value = max_value
3750
if initial_value is not None:
@@ -48,12 +61,14 @@ def __init__(
4861
initial_value=initial_value,
4962
)
5063

51-
def __get__(self, obj, cls=None):
64+
def __get__(
65+
self, obj: Optional[Service], cls: Optional[Type[Service]] = None
66+
) -> Union[int, "IntCharacteristic"]:
5267
if obj is None:
5368
return self
5469
return super().__get__(obj)[0]
5570

56-
def __set__(self, obj, value):
71+
def __set__(self, obj: Service, value: int) -> None:
5772
if not self._min_value <= value <= self._max_value:
5873
raise ValueError("out of range")
5974
super().__set__(obj, (value,))
@@ -63,45 +78,55 @@ class Int8Characteristic(IntCharacteristic):
6378
"""Int8 number."""
6479

6580
# pylint: disable=too-few-public-methods
66-
def __init__(self, *, min_value=-128, max_value=127, **kwargs):
81+
def __init__(
82+
self, *, min_value: int = -128, max_value: int = 127, **kwargs
83+
) -> None:
6784
super().__init__("<b", min_value, max_value, **kwargs)
6885

6986

7087
class Uint8Characteristic(IntCharacteristic):
7188
"""Uint8 number."""
7289

7390
# pylint: disable=too-few-public-methods
74-
def __init__(self, *, min_value=0, max_value=0xFF, **kwargs):
91+
def __init__(self, *, min_value: int = 0, max_value: int = 0xFF, **kwargs) -> None:
7592
super().__init__("<B", min_value, max_value, **kwargs)
7693

7794

7895
class Int16Characteristic(IntCharacteristic):
7996
"""Int16 number."""
8097

8198
# pylint: disable=too-few-public-methods
82-
def __init__(self, *, min_value=-32768, max_value=32767, **kwargs):
99+
def __init__(
100+
self, *, min_value: int = -32768, max_value: int = 32767, **kwargs
101+
) -> None:
83102
super().__init__("<h", min_value, max_value, **kwargs)
84103

85104

86105
class Uint16Characteristic(IntCharacteristic):
87106
"""Uint16 number."""
88107

89108
# pylint: disable=too-few-public-methods
90-
def __init__(self, *, min_value=0, max_value=0xFFFF, **kwargs):
109+
def __init__(
110+
self, *, min_value: int = 0, max_value: int = 0xFFFF, **kwargs
111+
) -> None:
91112
super().__init__("<H", min_value, max_value, **kwargs)
92113

93114

94115
class Int32Characteristic(IntCharacteristic):
95116
"""Int32 number."""
96117

97118
# pylint: disable=too-few-public-methods
98-
def __init__(self, *, min_value=-2147483648, max_value=2147483647, **kwargs):
119+
def __init__(
120+
self, *, min_value: int = -2147483648, max_value: int = 2147483647, **kwargs
121+
) -> None:
99122
super().__init__("<i", min_value, max_value, **kwargs)
100123

101124

102125
class Uint32Characteristic(IntCharacteristic):
103126
"""Uint32 number."""
104127

105128
# pylint: disable=too-few-public-methods
106-
def __init__(self, *, min_value=0, max_value=0xFFFFFFFF, **kwargs):
129+
def __init__(
130+
self, *, min_value: int = 0, max_value: int = 0xFFFFFFFF, **kwargs
131+
) -> None:
107132
super().__init__("<I", min_value, max_value, **kwargs)

0 commit comments

Comments
 (0)