On 2020-02-18 6:04 p.m., Chris Angelico wrote:
Too short, didn't read. Specifically, I'm not going to go digging
through your links to find code to justify why you want this feature.
Post some code here, or at very least, link directly to the code that
would be improved by this feature.

Soni, you're very close to my mental blocklist. Please put a bit more
effort into your posts to make it clear what you're actually
proposing, rather than making each of us do the work.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HVXVW7TPZNWBLMWU5D7BEGPPOVM773ZA/
Code of Conduct: http://python.org/psf/codeofconduct/
Alright, sorry.

The documentation states:

"ABDL expressions are regex-like constructs for matching and validating object structures. They can be used with JSON and similar formats, and even self-referential data structures." "ABDL expressions have the ability to iterate, index, validate and filter data structures, through the use of the syntax elements below." "An arrow is ``->`` and indicates indexing/iteration (Mappings, Sequences, Sets). Whether indexing or iteration is used is defined by the elements that follow, with iteration being used by default." "A variable is a sequence of alphanumeric characters, not starting with a digit. A ``(key, value)`` tuple containing the respective matched element will be identified by this name in the results dict."

And this sums up the core aspect of the library: the library is built on the idea of iterating "canonical keys" and their corresponding values, and validating and filtering them. ("[...] iteration being used by default", meaning indexing takes additional syntax - this is unlike some JSON and XML query languages where indexing takes /less/ syntax and filtering is generally highly limited and verbose.)

Iteration is done thusly:

def _pairs(obj):
    if isinstance(obj, collections.abc.Mapping):
        return iter(obj.items())
    elif isinstance(obj, collections.abc.Sequence):
        return iter(enumerate(obj, 0))
    elif isinstance(obj, collections.abc.Set):
        return iter(((e, e) for e in obj))
    else:
        # maybe there's more stuff I can implement later
        raise TypeError

I think having a proper protocol for this behaviour would be beneficial, as no (monkey)patching would be needed to add support for additional collections and data types. The comment saying there may be additional data types I've missed would then become irrelevant, as they'd be covered by __valid_getitem_requests__.

Sometimes you just want to treat everything as a (read-only) dict. Mostly when dealing with user input (e.g. configs), but not only.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BO75Q4QMZ7UDMSMK3F2MM5BBLKVV7ZME/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to