On 2/20/07, Greg Ewing <[EMAIL PROTECTED]> wrote:
> Raymond Hettinger wrote:
>
> > * Maintaining a live (self-updating) view is a bit tricky from an 
> > implementation
> > point-of-view.
>
> I don't understand what the alternative is. If mutating the
> underlying object doesn't affect the view, then you don't
> really have a view, just a copy of the data -- no different
> from the existing dict keys() etc.

FWIW, I didn't find the implementation tricky at all -- the views are
very small objects that simply contain a reference to the underlying
dict. All operations on the view defer to the dict one way or another.

The code in the PEP also shows how simple this is to do generically
for any underlying mapping object that implements __getitem__,
__contains__, __len__, and __iter__. (Or it will, once I am done
updating it. :-)

> If you're saying that you shouldn't be able to mutate the
> underlying object *through* the view, that's okay -- I don't
> mind if the views are read-only in some or all cases.

While the PEP has some mutability, the implementation currently has
all views be read-only, and I like this enough to want to keep it that
way.

>  > Let's make dicts as
> > simple as possible and then introduce a new collections module entry with 
> > the
> > views bells and whistles.
>
> If the view methods are only available on a special dict
> subclass and not on ordinary dicts, their usefulness will
> be severely crippled, so you wouldn't learn much from
> the experiment.

True. I'm also unclear on what "as simple as possible" would mean.
Perhaps delete iterkeys etc. and make keys etc. return iterators? That
was the *old* plan, which was never really challenged, and IMO it is
in every aspect inferior to the current plan.

BTW the PEP was incorrectly marked as accepted. I'll unmark it, and
remove the mutability.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to