
On 02/18/2020 12:24 AM, Serhiy Storchaka wrote:
1. What special method should be added, `__keys__` or `__items__`? The former returns keys, it needs to call `__getitem__` repeatedly to get values. The latter returns key-value pairs, it does not need to call `__getitem__`, but you should always pay the cost of creating a tuple even if you do not need values.
`__items__`
2. What type should they return?
* An iterator. * An iterable which can be iterated only once. Easy to implement in Python as generator methods. * An iterable which can be iterated multiple times. * More complex view object which may support other protocols (for example support `__or__` and `__and__`).
Whatever `dict.items()` returns, both for consistency and because `dict.items()` can become a simple alias for `dict.__items__`.
What do you think about this?
+1 -- ~Ethan~