Skip to content

Instantly share code, notes, and snippets.

@Callek
Created January 28, 2020 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Callek/74f2bcc77a0c261405df57ac50c870fb to your computer and use it in GitHub Desktop.
Save Callek/74f2bcc77a0c261405df57ac50c870fb to your computer and use it in GitHub Desktop.
# to_unicode {{{1
def to_unicode(line: AnyStr) -> str:
"""Avoid ``b'line'`` type messages in the logs.
Args:
line (str): The bytecode or unicode string.
Returns:
str: the unicode-decoded string, if ``line`` was a bytecode string.
Otherwise return ``line`` unmodified.
"""
try:
line = line.decode("utf-8")
except (UnicodeDecodeError, AttributeError):
pass
return line
src/scriptworker/utils.py:127: error: "str" has no attribute "decode"; maybe "encode"?
src/scriptworker/utils.py:127: error: Incompatible types in assignment (expression has type "str", variable has type "bytes")
src/scriptworker/utils.py:130: error: Incompatible return value type (got "bytes", expected "str")
src/scriptworker/log.py:81: error: Incompatible types in assignment (expression has type "str", variable has type "bytes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment