On Thu, 22 May 2008, Brandon Mintern wrote:
I think it makes the most sense, if this construct is adopted, to use __slots__ to control mutability. Someone more well-versed in the python object model should determine if this is actually a good idea.
-- Cheers, Leif
Whoops... I should have said "An implementation." I intended the implementation to be a specification for behavior and not the one-and-only implementation. Personally, I'm not especially familiar with using __slots__ in anything but standard usage, so I found it easier to show the code using __dict__. Certainly if __slots__ can be used, it avoids the need to write __setattr__ and to explicitly raise the AttributeError exception (which I already see is wrong because it doesn't support inheritance).
Don't take my word as gospel. I've only used __slots__ once, and it was at the suggest of another programmer in a kind of "I think this does what we want" suggestion, and we are still not entirely sure if it's doing what we think it's doing.