[Python-Dev] Re: Re: Re: Patch review: [ 1094542 ] add Bunch type
to collections module
Fernando Perez
fperez.net at gmail.com
Fri Jan 28 02:31:55 CET 2005
Steven Bethard wrote:
> 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:
[...]
Of course, you are right.
However, I think it would perhaps be best to advertise any methods of Bunch as
strictly classmethods from day 1. Otherwise, you can have:
b = Bunch()
b.update(otherdict) -> otherdict happens to have an 'update' key
... more code
b.update(someotherdict) -> boom! update is not callable
If all Bunch methods are officially presented always as classmethods, users can
simply expect that all attributes of a bunch are meant to store data, without
any instance methods at all.
Regards,
f
More information about the Python-Dev
mailing list