Skip to content

Commit 3e28b40

Browse files
author
Pedro Viana Schroeder
committed
Add missing type annotations
1 parent 340c62e commit 3e28b40

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

adafruit_irremote.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from __future__ import annotations
6+
57
"""
68
`adafruit_irremote`
79
====================================================
@@ -54,6 +56,11 @@
5456
from collections import namedtuple
5557
import time
5658

59+
try:
60+
from typing import List, NamedTuple, Optional, Tuple
61+
except ImportError:
62+
pass
63+
5764
__version__ = "0.0.0+auto.0"
5865
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git"
5966

@@ -66,7 +73,7 @@ class IRNECRepeatException(Exception):
6673
"""Exception when a NEC repeat is decoded"""
6774

6875

69-
def bin_data(pulses):
76+
def bin_data(pulses: List) -> List[List]:
7077
"""Compute bins of pulse lengths where pulses are +-25% of the average.
7178
7279
:param list pulses: Input pulse lengths
@@ -89,7 +96,7 @@ def bin_data(pulses):
8996
return bins
9097

9198

92-
def decode_bits(pulses):
99+
def decode_bits(pulses: List) -> NamedTuple:
93100
"""Decode the pulses into bits."""
94101
# pylint: disable=too-many-branches,too-many-statements
95102

@@ -211,12 +218,12 @@ class NonblockingGenericDecode:
211218
... ...
212219
"""
213220

214-
def __init__(self, pulses, max_pulse=10_000):
221+
def __init__(self, pulses: List, max_pulse: int = 10_000) -> None:
215222
self.pulses = pulses # PulseIn
216223
self.max_pulse = max_pulse
217224
self._unparsed_pulses = [] # internal buffer of partial messages
218225

219-
def read(self):
226+
def read(self) -> None:
220227
"""
221228
Consume all pulses from PulseIn. Yield decoded messages, if any.
222229
@@ -254,11 +261,11 @@ class GenericDecode:
254261
# this here for back-compat, hence we disable pylint for that specific
255262
# complaint.
256263

257-
def bin_data(self, pulses): # pylint: disable=no-self-use
264+
def bin_data(self, pulses: List) -> List[List]: # pylint: disable=no-self-use
258265
"Wraps the top-level function bin_data for backward-compatibility."
259266
return bin_data(pulses)
260267

261-
def decode_bits(self, pulses): # pylint: disable=no-self-use
268+
def decode_bits(self, pulses: List) -> Tuple: # pylint: disable=no-self-use
262269
"Wraps the top-level function decode_bits for backward-compatibility."
263270
result = decode_bits(pulses)
264271
if isinstance(result, NECRepeatIRMessage):
@@ -267,9 +274,9 @@ def decode_bits(self, pulses): # pylint: disable=no-self-use
267274
raise IRDecodeException("10 pulses minimum")
268275
return result.code
269276

270-
def _read_pulses_non_blocking(
271-
self, input_pulses, max_pulse=10000, pulse_window=0.10
272-
): # pylint: disable=no-self-use
277+
def _read_pulses_non_blocking( # pylint: disable=no-self-use
278+
self, input_pulses: List, max_pulse: int = 10000, pulse_window: float = 0.10
279+
) -> Optional[List]:
273280
"""Read out a burst of pulses without blocking until pulses stop for a specified
274281
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
275282
@@ -303,13 +310,13 @@ def _read_pulses_non_blocking(
303310

304311
def read_pulses(
305312
self,
306-
input_pulses,
313+
input_pulses: list,
307314
*,
308-
max_pulse=10000,
309-
blocking=True,
310-
pulse_window=0.10,
311-
blocking_delay=0.10,
312-
):
315+
max_pulse: int = 10000,
316+
blocking: bool = True,
317+
pulse_window: float = 0.10,
318+
blocking_delay: float = 0.10,
319+
) -> Optional[List]:
313320
"""Read out a burst of pulses until pulses stop for a specified
314321
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
315322
@@ -341,14 +348,24 @@ class GenericTransmit:
341348
:param bool debug: Enable debug output, default False
342349
"""
343350

344-
def __init__(self, header, one, zero, trail, *, debug=False):
351+
def __init__(
352+
self, header: int, one: int, zero: int, trail: int, *, debug: bool = False
353+
) -> None:
345354
self.header = header
346355
self.one = one
347356
self.zero = zero
348357
self.trail = trail
349358
self.debug = debug
350359

351-
def transmit(self, pulseout, data, *, repeat=0, delay=0, nbits=None):
360+
def transmit(
361+
self,
362+
pulseout: PulseOut,
363+
data: bytearray,
364+
*,
365+
repeat: int = 0,
366+
delay: int = 0,
367+
nbits: Optional[int] = None,
368+
) -> None:
352369
"""Transmit the ``data`` using the ``pulseout``.
353370
354371
:param pulseio.PulseOut pulseout: PulseOut to transmit on

0 commit comments

Comments
 (0)