Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buf1 != buf2 doesn't work in python2 #398

Closed
Yggdroot opened this issue May 21, 2019 · 2 comments
Closed

buf1 != buf2 doesn't work in python2 #398

Yggdroot opened this issue May 21, 2019 · 2 comments
Labels

Comments

@Yggdroot
Copy link

  • nvim --version: NVIM v0.4.0-758-g9e0982a1a
  • Vim (version: ) behaves differently? yes
  • Operating system/version: Linux
  • Terminal name/version:
  • $TERM:

Steps to reproduce using nvim -u NORC

nvim -u NORC

Suppose there is a file bug.vim:

py << EOF
import vim

aaa = vim.current.buffer
print(aaa == vim.current.buffer, aaa != vim.current.buffer)

EOF

Source the file: so %

This bug only happen when using python2, It works well for python3.

Actual behaviour

Result is (True, True) .

Expected behaviour

Result is (True, False) .

@bfredl
Copy link
Member

bfredl commented May 21, 2019

The reason is python2 doesn't have implicit __ne__ unlike python3. https://stackoverflow.com/questions/4352244/python-should-i-implement-ne-operator-based-on-eq

@bfredl bfredl transferred this issue from neovim/neovim May 21, 2019
@bfredl bfredl changed the title != is invalid buf1 != buf2 doesn't work in python2 May 21, 2019
@justinmk justinmk added the bug label May 21, 2019
@noelevans
Copy link
Contributor

noelevans commented Jun 21, 2019

I have a fix for this. It passes for both python 2.7 and 3.7.

While adding the unit test for the change, I also fixed a warning on test_buffer.py:96. Previously the module printed the warning below when run with python 3.7:
/home/noel/repo/pynvim/test/test_buffer.py:96: DeprecationWarning: invalid escape sequence \s
assert vim.options['define'] == '^\s*#\s*define'

I'm sending the pull request now

noelevans added a commit to noelevans/pynvim that referenced this issue Jun 21, 2019
Adding __ne__ function to pynvim.api.buffer.Buffer to correctly test
two buffers are not equal in Python 2. Test added to demonstrate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants