@@ -220,6 +220,9 @@ def __repr__(self):
220
220
def __eq__ (self , other ):
221
221
return isinstance (other , Root )
222
222
223
+ def __hash__ (self ):
224
+ return hash ('$' )
225
+
223
226
224
227
class This (JSONPath ):
225
228
"""
@@ -244,6 +247,9 @@ def __repr__(self):
244
247
def __eq__ (self , other ):
245
248
return isinstance (other , This )
246
249
250
+ def __hash__ (self ):
251
+ return hash ('this' )
252
+
247
253
248
254
class Child (JSONPath ):
249
255
"""
@@ -302,6 +308,9 @@ def __str__(self):
302
308
def __repr__ (self ):
303
309
return '%s(%r, %r)' % (self .__class__ .__name__ , self .left , self .right )
304
310
311
+ def __hash__ (self ):
312
+ return hash ((self .left , self .right ))
313
+
305
314
306
315
class Parent (JSONPath ):
307
316
"""
@@ -323,6 +332,9 @@ def __str__(self):
323
332
def __repr__ (self ):
324
333
return 'Parent()'
325
334
335
+ def __hash__ (self ):
336
+ return hash ('parent' )
337
+
326
338
327
339
class Where (JSONPath ):
328
340
"""
@@ -357,6 +369,9 @@ def __str__(self):
357
369
def __eq__ (self , other ):
358
370
return isinstance (other , Where ) and other .left == self .left and other .right == self .right
359
371
372
+ def __hash__ (self ):
373
+ return hash ((self .left , self .right ))
374
+
360
375
class Descendants (JSONPath ):
361
376
"""
362
377
JSONPath that matches first the left expression then any descendant
@@ -469,6 +484,9 @@ def __eq__(self, other):
469
484
def __repr__ (self ):
470
485
return '%s(%r, %r)' % (self .__class__ .__name__ , self .left , self .right )
471
486
487
+ def __hash__ (self ):
488
+ return hash ((self .left , self .right ))
489
+
472
490
473
491
class Union (JSONPath ):
474
492
"""
@@ -490,6 +508,12 @@ def is_singular(self):
490
508
def find (self , data ):
491
509
return self .left .find (data ) + self .right .find (data )
492
510
511
+ def __eq__ (self , other ):
512
+ return isinstance (other , Union ) and self .left == other .left and self .right == other .right
513
+
514
+ def __hash__ (self ):
515
+ return hash ((self .left , self .right ))
516
+
493
517
class Intersect (JSONPath ):
494
518
"""
495
519
JSONPath for bits that match *both* patterns.
@@ -511,6 +535,12 @@ def is_singular(self):
511
535
def find (self , data ):
512
536
raise NotImplementedError ()
513
537
538
+ def __eq__ (self , other ):
539
+ return isinstance (other , Intersect ) and self .left == other .left and self .right == other .right
540
+
541
+ def __hash__ (self ):
542
+ return hash ((self .left , self .right ))
543
+
514
544
515
545
class Fields (JSONPath ):
516
546
"""
@@ -596,6 +626,9 @@ def __repr__(self):
596
626
def __eq__ (self , other ):
597
627
return isinstance (other , Fields ) and tuple (self .fields ) == tuple (other .fields )
598
628
629
+ def __hash__ (self ):
630
+ return hash (tuple (self .fields ))
631
+
599
632
600
633
class Index (JSONPath ):
601
634
"""
@@ -662,6 +695,9 @@ def _pad_value(self, value):
662
695
pad = self .index - len (value ) + 1
663
696
value += [{} for __ in range (pad )]
664
697
698
+ def __hash__ (self ):
699
+ return hash (self .index )
700
+
665
701
666
702
class Slice (JSONPath ):
667
703
"""
@@ -741,6 +777,9 @@ def __repr__(self):
741
777
def __eq__ (self , other ):
742
778
return isinstance (other , Slice ) and other .start == self .start and self .end == other .end and other .step == self .step
743
779
780
+ def __hash__ (self ):
781
+ return hash ((self .start , self .end , self .step ))
782
+
744
783
745
784
def _create_list_key (dict_ ):
746
785
"""
0 commit comments