jmespath / jmespath/jmespath.py

Matching against objects derived from base collection types

Open
#162 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.4k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

I would like to use this library to match against values derived like collections.MutableSequence and collections.MutableMapping. For example:

`
import collections

import jmespath

class MySequence( collections.MutableSequence ):

def __init__( self, data ):
self.data = data

def __delitem__( self, index ):
del self.data[index]

def __getitem__( self, index ):
return self.data[index]

def __len__( self ):
return len( self.data )

def __setitem__( self, index, value ):
self.data[index] = value

def insert( self, index, value ):
self.data.insert( index, value )

data = [
{"name": "Seattle", "state": "WA"},
{"name": "New York", "state": "NY"},
{"name": "Bellevue", "state": "WA"},
{"name": "Olympia", "state": "WA"}
]

print jmespath.compile( '[0]' ).search( data ) # --> {'state': 'WA', 'name': 'Seattle'}
print jmespath.compile( '[0]' ).search( MySequence( data ) ) # --> None
`
It seems like this should be doable by changing all instances of isinstance( foo, list ) to isinstance( foo, collections.MutableSequence ), as this will return True for the default list type.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.