Skip to content

Commit 2a2225a

Browse files
authored
Merge pull request #15 from tekktrik/dod/typing-correction-just-blinka
Type annotation corrections
2 parents 21161ae + 12fe3db commit 2a2225a

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

adafruit_binascii.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
2424
"""
2525
try:
26+
from typing import Union
27+
from circuitpython_typing import ReadableBuffer
2628
from binascii import hexlify, unhexlify
2729
except ImportError:
2830
pass
@@ -63,11 +65,12 @@ class Error(Exception):
6365

6466
if not "unhexlify" in globals():
6567
# pylint: disable=function-redefined
66-
def unhexlify(hexstr: str) -> bytes:
68+
def unhexlify(hexstr: Union[str, ReadableBuffer]) -> bytes:
6769
"""Return the binary data represented by hexstr.
68-
:param str hexstr: Hexadecimal string.
6970
71+
:param str|ReadableBuffer hexstr: Hexadecimal string.
7072
"""
73+
7174
if len(hexstr) % 2 != 0:
7275
raise Error("Odd-length string")
7376

@@ -76,18 +79,18 @@ def unhexlify(hexstr: str) -> bytes:
7679

7780
if not "hexlify" in globals():
7881
# pylint: disable=function-redefined
79-
def hexlify(data: bytes) -> bytes:
82+
def hexlify(data: ReadableBuffer) -> bytes:
8083
"""Return the hexadecimal representation of the
8184
binary data. Every byte of data is converted into
8285
the corresponding 2-digit hex representation.
8386
The returned bytes object is therefore twice
8487
as long as the length of data.
8588
8689
:param bytes data: Binary data, as bytes.
87-
8890
"""
8991
if not data:
9092
raise TypeError("Data provided is zero-length")
93+
9194
data = "".join("%02x" % i for i in data)
9295
return bytes(data, "utf-8")
9396

@@ -106,12 +109,12 @@ def _transform(n: int) -> str:
106109
assert len(TABLE_A2B_B64) == 256
107110

108111

109-
def a2b_base64(b64_data: bytes) -> bytes:
112+
def a2b_base64(b64_data: ReadableBuffer) -> bytes:
110113
"""Convert a block of base64 data back to binary and return the binary data.
111114
112115
:param bytes b64_data: Base64 data.
113-
114116
"""
117+
115118
res = []
116119
quad_pos = 0
117120
leftchar = 0
@@ -148,12 +151,12 @@ def a2b_base64(b64_data: bytes) -> bytes:
148151
return b"".join(res)
149152

150153

151-
def b2a_base64(bin_data: bytes) -> bytes:
154+
def b2a_base64(bin_data: ReadableBuffer) -> bytes:
152155
"""Convert binary data to a line of ASCII characters in base64 coding.
153156
154-
:param bytes bin_data: Binary data string, as bytes
155-
157+
:param ReadableBuffer bin_data: Binary data string, as bytes
156158
"""
159+
157160
newlength = (len(bin_data) + 2) // 3
158161
newlength = newlength * 4 + 1
159162
res = []

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
#
33
# SPDX-License-Identifier: Unlicense
44

5-
Adafruit-Blinka
5+
Adafruit-Blinka>=7.2.3

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# Author details
3434
author="Adafruit Industries",
3535
author_email="circuitpython@adafruit.com",
36-
install_requires=["Adafruit-Blinka"],
36+
install_requires=["Adafruit-Blinka>=7.2.3"],
3737
# Choose your license
3838
license="MIT",
3939
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)