Correct type for a simple “bag of attributes” namespace object

Roy Smith roy at panix.com
Sun Aug 3 10:36:23 EDT 2014


In article <mailman.12582.1407072928.18130.python-list at python.org>,
 Chris Angelico <rosuav at gmail.com> wrote:

> On Sun, Aug 3, 2014 at 11:25 PM, Roy Smith <roy at panix.com> wrote:
> > in which case, I've said, "make Foos just like objects, except for, oh,
> > never mind, there aren't any differences".  But, in reality, the system
> > bolted on the ability to have user-defined attributes without telling
> > me.  I don't think it's unreasonable to be surprised at that.
> 
> I agree that this is slightly surprising. However, imagine if it were
> the other way:
> 
> class Foo(object):
>     x = 1
>     def __init__(self): self.y = 2
> 
> These would throw errors, unless you explicitly disable __slots__
> processing. When there's two ways to do things and both would be
> surprising, you pick the one that's going to be less of a surprise, or
> surprising less often, and accept it. That doesn't mean it's not a
> problem, but it's better than the alternative.
> 
> ChrisA

I'm not following you at all.  What does "the other way" mean, and how 
would that cause the above to generate errors, and what does this have 
to do with __slots__?



More information about the Python-list mailing list