Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsonpath_ng/jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ def _pad_value(self, value):
value += [{} for __ in range(pad)]

def __hash__(self):
return hash(self.index)
return hash(self.indices)


class Slice(JSONPath):
Expand Down
14 changes: 13 additions & 1 deletion tests/test_jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from typing import Callable
from jsonpath_ng.ext.parser import parse as ext_parse
from jsonpath_ng.jsonpath import DatumInContext, Fields, Root, This
from jsonpath_ng.jsonpath import DatumInContext, Fields, Index, Root, This
from jsonpath_ng.lexer import JsonPathLexerError
from jsonpath_ng.parser import parse as base_parse
from jsonpath_ng import JSONPath
Expand Down Expand Up @@ -435,3 +435,15 @@ def test_nested_index_auto_id(auto_id_field, parse, string, target):
def test_invalid_hyphenation_in_key():
with pytest.raises(JsonPathLexerError):
base_parse("foo.-baz")


def test_index_hashable():
idx = Index(0)
assert hash(idx) == hash((0,))
assert {idx: "value"}[idx] == "value"


def test_index_multi_indices_hashable():
idx = Index(0, 1, 2)
assert hash(idx) == hash((0, 1, 2))
assert {idx: "value"}[idx] == "value"