Skip to content

[Python3] "".decode fails with: 'str' object has no attribute 'decode'. (Py3 'str' is Py2 'unicode')

Seen in https://github.com/Homebrew/homebrew-core/pull/98414

  Traceback (most recent call last):
    File "/opt/homebrew/Cellar/ski/6.13/bin/ski", line 484, in <module>
      reset = (curses.tigetstr("sgr0") or "").decode("ascii")
  AttributeError: 'str' object has no attribute 'decode'

Specifically at https://gitlab.com/esr/ski/-/blob/6.13/ski#L484

    reset = (curses.tigetstr("sgr0") or "").decode("ascii")

Here, the or uses a "" of type str in Python3 (previously unicode in Python2). The problem is decode is for bytes (previously str in Python2).

So, need some compatibility changes to support both Python2 and Python3.