prompt-toolkit/pyvim

TypeError: encode() argument 1 must be string, not None

ilovezfs opened this issue · 0 comments

This seems to be basically the same issue as aws/aws-cli#1844

During the test block in Homebrew,

==> /usr/local/Cellar/pyvim/0.0.21/bin/pyvim --help
Traceback (most recent call last):
  File "/usr/local/Cellar/pyvim/0.0.21/libexec/bin/pyvim", line 11, in <module>
    load_entry_point('pyvim==0.0.21', 'console_scripts', 'pyvim')()
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 570, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2751, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2405, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2411, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/Cellar/pyvim/0.0.21/libexec/lib/python2.7/site-packages/pyvim/entry_points/run_pyvim.py", line 17, in <module>
    from pyvim.editor import Editor
  File "/usr/local/Cellar/pyvim/0.0.21/libexec/lib/python2.7/site-packages/pyvim/editor.py", line 29, in <module>
    from .layout import EditorLayout, get_terminal_title
  File "/usr/local/Cellar/pyvim/0.0.21/libexec/lib/python2.7/site-packages/pyvim/layout.py", line 50, in <module>
    TABSTOP_DOT = _try_char('\u2508', '.')
  File "/usr/local/Cellar/pyvim/0.0.21/libexec/lib/python2.7/site-packages/pyvim/layout.py", line 44, in _try_char
    if character.encode(encoding, 'replace') == b'?':
TypeError: encode() argument 1 must be string, not None

But run from a regular terminal session,

iMac-TMP:homebrew-core joe$ /usr/local/Cellar/pyvim/0.0.21/bin/pyvim --help
pyvim: Pure Python Vim clone.
Usage:
    pyvim [-p] [-o] [-O] [-u <pyvimrc>] [<location>...]

Options:
    -p           : Open files in tab pages.
    -o           : Split horizontally.
    -O           : Split vertically.
    -u <pyvimrc> : Use this .pyvimrc file instead.

I can hack around this by doing

    require "pty"
    PTY.spawn(bin/"pyvim", "--help") do |r, _w, _pid|
      assert_match "Vim clone", r.read
    end

instead of just

    system "#{bin}/pyvim", "--help"

A minimal fix would be checking in pyvim/layout.py in _try_char if encoding is None and setting it to 'ascii' if it is, as aws/aws-cli#1844 does. But maybe there is a better approach.