[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-19 Thread Kyle Stanley
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 cre

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Steven D'Aprano
On Tue, Feb 18, 2020 at 11:47:16AM -0800, Ethan Furman wrote: > Whatever `dict.items()` returns, both for consistency and because > `dict.items()` can become a simple alias for `dict.__items__`. That means that every object wanting to make use of this protocol needs to create a complex set-like

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread waszka23
+1 on the proposed addition. I think that `__items__` would be a better choice for the method name. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lis

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Ethan Furman
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 alway

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Serhiy Storchaka
18.02.20 19:00, Soni L. пише: I like __items__. additionally, lists should implement it to return enumerate(self), and sets should implement it to return (v, v for v in self), and as such there should be no requirement with regards to __items__ and __iter__, and whether __iter__ returns keys or

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Soni L.
On 2020-02-18 5:34 a.m., Chris Angelico wrote: On Tue, Feb 18, 2020 at 7:25 PM Serhiy Storchaka wrote: > * The keys() method is not called in the dict constructor. Just the > existence of the keys attribute is checked, its value is not used. Given that that's already been the case, my prefer

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Guido van Rossum
+1 On Tue, Feb 18, 2020 at 5:01 AM Andrew Svetlov wrote: > Sounds reasonable to me > > On Tue, Feb 18, 2020 at 12:32 PM Serhiy Storchaka > wrote: > > > > 18.02.20 10:34, Chris Angelico пише: > > > Given that that's already been the case, my preferred colour for the > > > bike shed is... > > > >

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Andrew Svetlov
Sounds reasonable to me On Tue, Feb 18, 2020 at 12:32 PM Serhiy Storchaka wrote: > > 18.02.20 10:34, Chris Angelico пише: > > Given that that's already been the case, my preferred colour for the > > bike shed is... > > Thank you for your feedback. This is my preferable color too, for both > parts

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Serhiy Storchaka
18.02.20 10:34, Chris Angelico пише: Given that that's already been the case, my preferred colour for the bike shed is... Thank you for your feedback. This is my preferable color too, for both parts. ___ Python-ideas mailing list -- python-ideas@pyt

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Chris Angelico
On Tue, Feb 18, 2020 at 7:25 PM Serhiy Storchaka wrote: > * The keys() method is not called in the dict constructor. Just the > existence of the keys attribute is checked, its value is not used. Given that that's already been the case, my preferred colour for the bike shed is... > 1. What specia