[Python-3000] Iterators for dict keys, values, and items == annoying :)

Nick Coghlan ncoghlan at gmail.com
Thu Mar 30 11:55:24 CEST 2006


Greg Ewing wrote:
> Brett Cannon wrote:
>> Without a direct reason in terms of the language needing a
>> standardization of an interface, perhaps we just don't need
>  > views.
> 
> On the contrary, views are a very useful idea, *as a
> design pattern*. What we *don't* need in Python, as far
> as I can see, is any formalised protocols or interfaces
> for views, because there's nothing that can be said about
> them in general.
> 
> Thinking that "having views" means "having a formally
> defined interface for views" is a mindset that comes
> from B&D languages like Java. It doesn't apply to
> Python at all.

+lots

All I think we're currently missing is an idea of 'what magic methods does an 
object need to provide in order to pretend to be a container, rather than just 
an iterable?'

Change dict.keys/values/items to return views which implement that set of 
methods, and all should be good.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list