Add a __valid_getitem_requests__ protocol
18 Feb
2020
18 Feb
'20
11:43 a.m.
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.
1512
Age (days ago)
1521
Last active (days ago)
34 comments
14 participants
participants (14)
-
Andrew Barnert
-
Antoine Pitrou
-
Brett Cannon
-
C. Titus Brown
-
Chris Angelico
-
Christopher Barker
-
Ethan Furman
-
Guido van Rossum
-
Kyle Stanley
-
MRAB
-
Paul Moore
-
Rhodri James
-
Soni L.
-
Steven D'Aprano