[Python-Dev] Re: Re: Patch review: [ 1094542 ] add Bunch type to collections module

Steven Bethard steven.bethard at gmail.com
Fri Jan 28 02:25:57 CET 2005


Fernando Perez wrote:
> Steven Bethard wrote:
> > I'm probably not willing to budge much on adding dict-style methods --
> > if you want a dict, use a dict.  But if people think they're
> > necessary, there are a few methods from Struct that I wouldn't be too
> > upset if I had to add, e.g. clear, copy, etc.  But I'm going to need
> > more feedback before I make any changes like this.
> 
> You already have update(), which by the way precludes a bunch storing an
> 'update' attribute.

Well, actually, you can have an update attribute, but then you have to
call update from the class instead of the instance:

py> from bunch import Bunch
py> b = Bunch(update=3)
py> b.update
3
py> b.update(Bunch(hi=4))
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: 'int' object is not callable
py> Bunch.update(b, Bunch(hi=4))
py> b.hi
4

> Bunch.update(mybunch, othermapping) -> modifies mybunch.

Yup, that works currently.  As is normal for new-style classes
(AFAIK), the methods are stored in the class object, so assigning an
'update' attribute to an instance just hides the method in the class. 
You can still reach the method by invoking it from the class and
passing it an instance as the first argument.

Steve
-- 
You can wordify anything if you just verb it.
        --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list