type hinted bytesconverter

master
Kevin Froman 2020-03-16 02:55:36 -05:00
parent 9575352e3e
commit 68678177ed
1 changed files with 5 additions and 3 deletions

View File

@ -1,12 +1,14 @@
def str_to_bytes(data):
'''Converts a string to bytes with .encode()'''
def str_to_bytes(data: str) -> bytes:
'''Convert a string to bytes with .encode(), utf8'''
try:
data = data.encode('UTF-8')
except AttributeError:
pass
return data
def bytes_to_str(data):
def bytes_to_str(data: bytes) -> str:
"""Convert bytes to strings with .decode(), utf8"""
try:
data = data.decode('UTF-8')
except AttributeError: