code: def wcswidth(pwcs, n=None):
      
      # pylint: disable=C0103
      #         Invalid argument name "n"
  
      end = len(pwcs) if n is None else n
      idx = slice(0, end)
      width = 0
      for char in pwcs[idx]:
          wcw = wcwidth(char)
          if wcw < 0:
              return -1
          else:
              width += wcw
      return width
docs: Given a unicode string, return its printable length on a terminal.
  
      Return the width, in cells, necessary to display the first ``n``
      characters of the unicode string ``pwcs``.  When ``n`` is None (default),
      return the length of the entire string.
  
      Returns ``-1`` if a non-printable character is encountered.