Skip to content

Add type hints #13

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

Merged
merged 1 commit into from
Dec 5, 2021
Merged
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
10 changes: 5 additions & 5 deletions adafruit_binascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Error(Exception):

if not "unhexlify" in globals():
# pylint: disable=function-redefined
def unhexlify(hexstr):
def unhexlify(hexstr: str) -> bytes:
"""Return the binary data represented by hexstr.
:param str hexstr: Hexadecimal string.

Expand All @@ -76,7 +76,7 @@ def unhexlify(hexstr):

if not "hexlify" in globals():
# pylint: disable=function-redefined
def hexlify(data):
def hexlify(data: bytes) -> bytes:
"""Return the hexadecimal representation of the
binary data. Every byte of data is converted into
the corresponding 2-digit hex representation.
Expand All @@ -96,7 +96,7 @@ def hexlify(data):
A2B_HEX = unhexlify


def _transform(n):
def _transform(n: int) -> str:
if n == -1:
return "\xff"
return chr(n)
Expand All @@ -106,7 +106,7 @@ def _transform(n):
assert len(TABLE_A2B_B64) == 256


def a2b_base64(b64_data):
def a2b_base64(b64_data: str) -> bytes:
"""Convert a block of base64 data back to binary and return the binary data.

:param str b64_data: Base64 data.
Expand Down Expand Up @@ -148,7 +148,7 @@ def a2b_base64(b64_data):
return b"".join(res)


def b2a_base64(bin_data):
def b2a_base64(bin_data: str) -> bytes:
"""Convert binary data to a line of ASCII characters in base64 coding.

:param str bin_data: Binary data string, as bytes
Expand Down