Re: Warning when new attributes are added to classes at run time

2006-07-20 Thread Nick Vatamaniuc
Use __slots__ they will simply give you an error. But at the same time I don't think they are inheritable and in general you should only use slots for performance reasons (even then test before using). Or you could also simulate a __slots__ mechanism the way you are doing i.e. checking the attribu

Re: Warning when new attributes are added to classes at run time

2006-07-20 Thread Bruno Desthuilliers
Matthew Wilson wrote: > On Thu 20 Jul 2006 04:32:28 AM EDT, Bruno Desthuilliers wrote: (snip) > >>>class C1(C): >>> >>>standard_attributes = ['a1', 'a2'] >> >>DRY violation here. And a potential problem with inheritance (as always >>with class attributes). > > > Considering I had to

Re: Warning when new attributes are added to classes at run time

2006-07-20 Thread Matthew Wilson
On Thu 20 Jul 2006 04:32:28 AM EDT, Bruno Desthuilliers wrote: >> self.__dict__[name] = value > Make it: > object.__setattr__(self, name, value) > > Your approach will lead to strange results if you mix it with properties > or other descriptors... Thanks! >> cl

Re: Warning when new attributes are added to classes at run time

2006-07-20 Thread Bruno Desthuilliers
Matthew Wilson wrote: > I sometimes inadvertently create a new attribute on an object rather > update a value bound to an existing attribute. For example: > (snip) > > I meant to update c.a but I created a new c.A. I make this mistake > probably hourly. > > I suspect adding attributes at run t

Re: Warning when new attributes are added to classes at run time

2006-07-19 Thread Diez B. Roggisch
Matthew Wilson schrieb: > I sometimes inadvertently create a new attribute on an object rather > update a value bound to an existing attribute. For example: > > In [5]: class some_class(object): >...: def __init__(self, a=None): >...: self.a = a >...: >

Re: Warning when new attributes are added to classes at run time

2006-07-19 Thread jay graves
Matthew Wilson wrote: > I sometimes inadvertently create a new attribute on an object rather > update a value bound to an existing attribute. For example: > All comments are welcome. Is there a better way of implementing the > above class, OR, is this approach generally wrong-headed? Am I the o

Re: Warning when new attributes are added to classes at run time

2006-07-19 Thread Jean-Paul Calderone
On Wed, 19 Jul 2006 20:42:40 GMT, Matthew Wilson <[EMAIL PROTECTED]> wrote: > >I sometimes inadvertently create a new attribute on an object rather >update a value bound to an existing attribute. For example: > > [snip] Write more unit tests. If you have mistakes like this, they will fail and yo

Warning when new attributes are added to classes at run time

2006-07-19 Thread Matthew Wilson
I sometimes inadvertently create a new attribute on an object rather update a value bound to an existing attribute. For example: In [5]: class some_class(object): ...: def __init__(self, a=None): ...: self.a = a ...: In [6]: c = some_class(a=1) In