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
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
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
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
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
>...:
>
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
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
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