Skip to content

Commit edbe6fa

Browse files
committed
feat: hashable JSONPath filters
1 parent f493616 commit edbe6fa

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

jsonpath/selectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def __eq__(self, __value: object) -> bool:
576576
)
577577

578578
def __hash__(self) -> int:
579-
return hash((self.expression, self.token))
579+
return hash((str(self.expression), self.token))
580580

581581
def resolve( # noqa: PLR0912
582582
self, matches: Iterable[JSONPathMatch]

tests/test_ietf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,9 @@ async def coro() -> List[object]:
383383
return await path.findall_async(case.data)
384384

385385
assert asyncio.run(coro()) == case.want
386+
387+
388+
@pytest.mark.parametrize("case", TEST_CASES, ids=operator.attrgetter("description"))
389+
def test_hash_path(env: JSONPathEnvironment, case: Case) -> None:
390+
"""Test that paths are hashable."""
391+
hash(env.compile(case.path))

0 commit comments

Comments
 (0)