ericpan64 / pydian

Python framework for developer-friendly data interchange
MIT License
5 stars 0 forks source link

Fix `get` bug -- tuple index handling #11

Open ericpan64 opened 1 month ago

ericpan64 commented 1 month ago

Describe the bug

Seems like indexing into tuples (or things index-able besides lists) doesn't happen and silently errors

How To Reproduce

from pydian import get

tup = ('a', 'b')
some_dict = { 'tup_key': tup }
print(get(some_dict, 'tup_key[0]'))  # Expect `'a'`, got `None`
print(get(some_dict, 'tup_key'))  # Correctly gets tuple

Expected behavior

Index into the tuple

Additional context

ericpan64 commented 1 month ago

Alright: so it seems like JMESPath doesn't support tuple indexing, which makes sense because it's JSON-focused (and does a lot there). If pydian is to be the general data eng framework, it needs tuple support and other random things. It's time for a parser...

Look into pyparsing or parsimonious, and make a simple grammar (take ideas from JMESPath and give credit where credit is due)