Skip to content

Commit

Permalink
Fix translation of empty hash
Browse files Browse the repository at this point in the history
  • Loading branch information
813gan committed Sep 14, 2024
1 parent b6f5c8e commit 560ec90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion emacspy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ cdef class EmacsValue:

keys, values = \
EmacsValue.wrap(env.funcall(env, hash_table_to_lists, 1, &hash_src)).to_python_type()
return dict(zip(keys, values))
if keys and values:
return dict(zip(keys, values))
return dict()

def to_python_type(self):
my_type = self.type()
Expand Down
5 changes: 4 additions & 1 deletion tests/test.el
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,17 @@
(ert-deftest ert-test-emacspy-data-hash ()
(should (functionp 'emacspy--hash-table-to-lists))
(let ((hash (make-hash-table))
(nhash (make-hash-table)))
(nhash (make-hash-table))
(empty-hash (make-hash-table)))
(puthash 1 "test" hash)
(puthash 2 nil hash)
(puthash "list" '(1) hash)

(puthash "key" 1 nhash)
(puthash "hash" nhash hash)

(should (py-set-global "test" empty-hash "test_empty_hash"))

(should (py-set-global "test" hash "test_hash"))
(should (py-run-string "test" "test_hash[1]=='test'"))
(should (py-run-string "test" "test_hash[2]==False"))
Expand Down

0 comments on commit 560ec90

Please sign in to comment.