Skip to content

Commit f44e171

Browse files
committed
api: make remote objects hashable on their identity
1 parent c033eac commit f44e171

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

neovim/api/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def __eq__(self, other):
1515
return (hasattr(other, 'code_data') and
1616
other.code_data == self.code_data)
1717

18+
def __hash__(self):
19+
"""Return hash based on remote object id."""
20+
return self.code_data.__hash__()
21+
1822

1923
class RemoteMap(object):
2024

test/test_vim.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,17 @@ def test_tabpages():
124124
vim.current.tabpage = vim.tabpages[1]
125125
eq(vim.tabpages[1], vim.current.tabpage)
126126
eq(vim.windows[1], vim.current.window)
127+
128+
129+
@with_setup(setup=cleanup)
130+
def test_hash():
131+
d = {}
132+
d[vim.current.buffer] = "alpha"
133+
eq(d[vim.current.buffer], "alpha")
134+
vim.command('new')
135+
d[vim.current.buffer] = "beta"
136+
eq(d[vim.current.buffer], "beta")
137+
vim.command('winc w')
138+
eq(d[vim.current.buffer], "alpha")
139+
vim.command('winc w')
140+
eq(d[vim.current.buffer], "beta")

0 commit comments

Comments
 (0)