It'd be nice to have a __valid_getitem_requests__ protocol that, if
present, yields pairs such that:
for key, value in items(obj):
assert obj[key] == value
for any obj. Note that this definition explicitly allows subsets, which
makes it useful for sequences and defaultdicts, as they can have all
sorts of keys (or even infinitely many in the case of defaultdict):
>>> [1, 2, 3, 4, 5][1]
2
>>> [1, 2, 3, 4, 5][1:3]
[2, 3]
>>> [1, 2, 3, 4, 5][-1]
5
and as such we should consider limiting the results for at least these 2
cases.
I currently use a similar idea in my code but I feel like having this
would make my code more extensible without ppl having to monkeypatch it.
_______________________________________________
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/N4L5JV3ZUD5CTFTTT4DDUASE6HODW5SK/
Code of Conduct: http://python.org/psf/codeofconduct/